Exemplo n.º 1
0
  /**
   * Return an ImageRecord containing the images pixel dimensions.
   *
   * @param file absolute file path to image
   * @return ImageRecord containing the images pixel dimensions
   */
  public static ImageRecord getImageDimensions(final String file) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Getting image dimensions from: {}", file);
    }

    final ImageRecord dim = new ImageRecord(file);
    final Opener o = new Opener();
    final ImagePlus imp = o.openImage(file);
    if (imp == null) {
      return null;
    }
    ImageProcessor ip = imp.getProcessor();
    final int width = ip.getWidth();
    final int height = ip.getHeight();

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug(
          "{} (width: {} | height: {})", file, Integer.toString(width), Integer.toString(height));
    }

    dim.setWidth(width);
    dim.setHeight(height);
    ip = null;
    return dim;
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws IOException, WriteException {
    // TODO code application logic here
    int cellNum = 0;
    double[] cTCF = new double[30];
    ImagePlus img = null;
    Opener op = new Opener();

    for (int i = 0; i < 30; i++) {
      String num = Integer.toString(i);
      img = op.openImage("E:/Photobleaching/Target/1/" + num + ".tif");

      ImageProcessor im = img.getProcessor().duplicate();
      // set region of interest for target cell
      im.setRoi(342, 668, 36, 36);
      double cellMean = im.getStatistics().mean;
      double cellArea = im.getStatistics().area;
      double cellIntensity = cellMean * cellArea;
      // --------------------------------------------------------------------------
      // calculate Integrated Density of background for target cell area
      // --------------------------------------------------------------------------
      ImageProcessor background1 = img.getProcessor().duplicate();
      // set region of interest for background
      background1.setRoi(341, 591, 21, 20);
      double backgroundMean1 = background1.getStatistics().mean;
      double backgroundIntensity1 = backgroundMean1 * cellArea;

      ImageProcessor background2 = img.getProcessor().duplicate();
      // set region of interest for background
      background2.setRoi(383, 641, 20, 20);
      double backgroundMean2 = background2.getStatistics().mean;
      double backgroundIntensity2 = backgroundMean2 * cellArea;

      double backgroundIntensity = (backgroundIntensity1 + backgroundIntensity2) / 2;
      // calculate corrected total cell fluorescence (CTCF)
      cTCF[cellNum] = cellIntensity - backgroundIntensity;
      cellNum = cellNum + 1;
    }

    WriteToExcel write = new WriteToExcel();
    write.write(1, cellNum, cTCF);
  }
Exemplo n.º 3
0
 public Image getImage(JCRNodeWrapper node) throws IOException, RepositoryException {
   File tmp = null;
   OutputStream os = null;
   try {
     tmp = File.createTempFile("image", null);
     Node contentNode = node.getNode(Constants.JCR_CONTENT);
     os = new BufferedOutputStream(new FileOutputStream(tmp));
     InputStream is = contentNode.getProperty(Constants.JCR_DATA).getBinary().getStream();
     try {
       IOUtils.copy(is, os);
     } finally {
       IOUtils.closeQuietly(os);
       IOUtils.closeQuietly(is);
     }
     Opener op = new Opener();
     ImagePlus ip = op.openImage(tmp.getPath());
     return new ImageJImage(node.getPath(), ip, op.getFileType(tmp.getPath()));
   } finally {
     IOUtils.closeQuietly(os);
     FileUtils.deleteQuietly(tmp);
   }
 }
Exemplo n.º 4
0
  public static String createThumbImage(String fileAbsolutePath, String fileSaveAsNameSuffix) {
    try {
      Opener opener = new Opener();
      ImagePlus imp = opener.openImage(fileAbsolutePath);
      ImageProcessor ip = imp.getProcessor();
      StackProcessor sp = new StackProcessor(imp.getStack(), ip);

      int width = imp.getWidth();
      int height = imp.getHeight();

      int cropWidth = 0;
      int cropHeight = 0;
      if (width > height) {
        cropWidth = height;
        cropHeight = height;
      } else {
        cropWidth = width;
        cropHeight = width;
      }
      int x = -1;
      int y = -1;
      if (width == height) {
        x = 0;
        y = 0;
      } else if (width > height) {
        x = (width - height) / 2;
        y = 0;
      } else if (width < height) {
        x = 0;
        y = (height - width) / 2;
      }
      ImageStack croppedStack = sp.crop(x, y, cropWidth, cropHeight);

      imp.setStack(null, croppedStack);

      sp = new StackProcessor(imp.getStack(), imp.getProcessor());

      ImageStack resizedStack = sp.resize(100, 100, true);
      imp.setStack(null, resizedStack);

      File generateSourcePath = new File(fileAbsolutePath);

      StringBuffer filePath =
          new StringBuffer(generateSourcePath.getParentFile().getParentFile().getAbsolutePath());

      File generatePath = new File(filePath.toString() + File.separator + "generate");
      if (!generatePath.exists()) {
        generatePath.mkdirs();
      }
      filePath = new StringBuffer(generateSourcePath.getName());
      filePath.replace(filePath.lastIndexOf("."), filePath.lastIndexOf("."), fileSaveAsNameSuffix);

      String saveAsFilePath = generatePath.getAbsolutePath() + File.separator + filePath.toString();

      IJ.save(imp, saveAsFilePath);
      return saveAsFilePath;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }