Exemplo n.º 1
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   Undo.setup(Undo.ROI, imp);
   Roi roi2 = null;
   if (roi.getType() == Roi.LINE) {
     double width = roi.getStrokeWidth();
     if (width <= 1.0) roi.setStrokeWidth(1.0000001);
     FloatPolygon p = roi.getFloatPolygon();
     roi.setStrokeWidth(width);
     roi2 = new PolygonRoi(p, Roi.POLYGON);
     roi2.setDrawOffset(roi.getDrawOffset());
   } else {
     ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
     ip2.setColor(255);
     roi.drawPixels(ip2);
     // new ImagePlus("ip2", ip2.duplicate()).show();
     ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
     ThresholdToSelection tts = new ThresholdToSelection();
     roi2 = tts.convert(ip2);
   }
   transferProperties(roi, roi2);
   roi2.setStrokeWidth(0);
   Color c = roi2.getStrokeColor();
   if (c != null) // remove any transparency
   roi2.setStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue()));
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
Exemplo n.º 2
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() == 1) {
     IJ.error("Line to Area", "Straight line width must be > 1");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE) ip2.fillPolygon(roi.getPolygon());
   else {
     roi.drawPixels(ip2);
     // BufferedImage bi = new BufferedImage(imp.getWidth(), imp.getHeight(),
     // BufferedImage.TYPE_BYTE_GRAY);
     // Graphics g = bi.getGraphics();
     // Roi roi2 = (Roi)roi.clone();
     // roi2.setStrokeColor(Color.white);
     // roi2.drawOverlay(g);
     // ip2 = new ByteProcessor(bi);
   }
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
 public void setThreshold(double minThreshold, double maxThreshold, int lutUpdate) {
   if (minThreshold == NO_THRESHOLD) {
     resetThreshold();
     return;
   }
   if (max > min) {
     double minT = Math.round(((minThreshold - min) / (max - min)) * 255.0);
     double maxT = Math.round(((maxThreshold - min) / (max - min)) * 255.0);
     super.setThreshold(minT, maxT, lutUpdate); // update LUT
   } else super.resetThreshold();
   this.minThreshold = minThreshold;
   this.maxThreshold = maxThreshold;
 }
Exemplo n.º 4
0
 void createMaskFromThreshold(ImagePlus imp) {
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMinThreshold() == ImageProcessor.NO_THRESHOLD) {
     IJ.error("Create Mask", "Area selection or thresholded image required");
     return;
   }
   double t1 = ip.getMinThreshold();
   double t2 = ip.getMaxThreshold();
   IJ.run("Duplicate...", "title=mask");
   ImagePlus imp2 = WindowManager.getCurrentImage();
   ImageProcessor ip2 = imp2.getProcessor();
   ip2.setThreshold(t1, t2, ImageProcessor.NO_LUT_UPDATE);
   IJ.run("Convert to Mask");
 }
 public void run(ImageProcessor ip) {
   if (canceled) return;
   slice++;
   if (imp.getStackSize() > 1 && processStack) imp.setSlice(slice);
   if (imp.getType() == ImagePlus.COLOR_RGB) {
     ip = (ImageProcessor) imp.getProperty("Mask");
     ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   }
   if (!analyze(imp, ip)) canceled = true;
   if (slice == imp.getStackSize()) {
     imp.updateAndDraw();
     if (saveRoi != null) imp.setRoi(saveRoi);
   }
 }
Exemplo n.º 6
0
 void lineToArea(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null || !roi.isLine()) {
     IJ.error("Line to Area", "Line selection required");
     return;
   }
   ImageProcessor ip2 = new ByteProcessor(imp.getWidth(), imp.getHeight());
   ip2.setColor(255);
   if (roi.getType() == Roi.LINE && roi.getStrokeWidth() > 1) ip2.fillPolygon(roi.getPolygon());
   else roi.drawPixels(ip2);
   // new ImagePlus("ip2", ip2.duplicate()).show();
   ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE);
   ThresholdToSelection tts = new ThresholdToSelection();
   Roi roi2 = tts.convert(ip2);
   imp.setRoi(roi2);
   Roi.previousRoi = (Roi) roi.clone();
 }
Exemplo n.º 7
0
 void createSelectionFromMask(ImagePlus imp) {
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMinThreshold() != ImageProcessor.NO_THRESHOLD) {
     IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", "");
     return;
   }
   if (!ip.isBinary()) {
     IJ.error(
         "Create Selection",
         "This command creates a composite selection from\n"
             + "a mask (8-bit binary image with white background)\n"
             + "or from an image that has been thresholded using\n"
             + "the Image>Adjust>Threshold tool. The current\n"
             + "image is not a mask and has not been thresholded.");
     return;
   }
   int threshold = ip.isInvertedLut() ? 255 : 0;
   ip.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE);
   IJ.runPlugIn("ij.plugin.filter.ThresholdToSelection", "");
 }
Exemplo n.º 8
0
  /* Method takes roi and substract its mean value from each frame in the image*/
  public static ImagePlus DarkNoiseRemoval(ImagePlus imp_in, Roi noise_roi) {
    ImagePlus imp_out = imp_in.duplicate();
    int size = imp_in.getImageStackSize();
    ImageProcessor ip = imp_out.getProcessor();
    double minThreshold = ip.getMinThreshold();
    double maxThreshold = ip.getMaxThreshold();
    Calibration cal = imp_in.getCalibration();
    int measurements = Analyzer.getMeasurements();
    int current = imp_in.getCurrentSlice();
    ImageStack stack = imp_in.getStack();
    for (int i = 1; i <= size; i++) {
      ip = stack.getProcessor(i);
      if (minThreshold != ImageProcessor.NO_THRESHOLD)
        ip.setThreshold(minThreshold, maxThreshold, ImageProcessor.NO_LUT_UPDATE);
      ip.setRoi(noise_roi);
      ImageStatistics stats = ImageStatistics.getStatistics(ip, measurements, cal);
      ip.resetRoi();
      ip.subtract(stats.mean);
      stack.setProcessor(ip, i);
    }

    imp_out.setStack(stack);
    return imp_out;
  }
Exemplo n.º 9
0
 private void makeBand(ImagePlus imp) {
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Make Band");
     return;
   }
   if (!roi.isArea()) {
     IJ.error("Make Band", "Area selection required");
     return;
   }
   Calibration cal = imp.getCalibration();
   double pixels = bandSize;
   double size = pixels * cal.pixelWidth;
   int decimalPlaces = 0;
   if ((int) size != size) decimalPlaces = 2;
   GenericDialog gd = new GenericDialog("Make Band");
   gd.addNumericField("Band Size:", size, decimalPlaces, 4, cal.getUnits());
   gd.showDialog();
   if (gd.wasCanceled()) return;
   size = gd.getNextNumber();
   if (Double.isNaN(size)) {
     IJ.error("Make Band", "invalid number");
     return;
   }
   int n = (int) Math.round(size / cal.pixelWidth);
   if (n > 255) {
     IJ.error("Make Band", "Cannot make bands wider that 255 pixels");
     return;
   }
   int width = imp.getWidth();
   int height = imp.getHeight();
   Rectangle r = roi.getBounds();
   ImageProcessor ip = roi.getMask();
   if (ip == null) {
     ip = new ByteProcessor(r.width, r.height);
     ip.invert();
   }
   ImageProcessor mask = new ByteProcessor(width, height);
   mask.insert(ip, r.x, r.y);
   ImagePlus edm = new ImagePlus("mask", mask);
   boolean saveBlackBackground = Prefs.blackBackground;
   Prefs.blackBackground = false;
   IJ.run(edm, "Distance Map", "");
   Prefs.blackBackground = saveBlackBackground;
   ip = edm.getProcessor();
   ip.setThreshold(0, n, ImageProcessor.NO_LUT_UPDATE);
   int xx = -1, yy = -1;
   for (int x = r.x; x < r.x + r.width; x++) {
     for (int y = r.y; y < r.y + r.height; y++) {
       if (ip.getPixel(x, y) < n) {
         xx = x;
         yy = y;
         break;
       }
     }
     if (xx >= 0 || yy >= 0) break;
   }
   int count = IJ.doWand(edm, xx, yy, 0, null);
   if (count <= 0) {
     IJ.error("Make Band", "Unable to make band");
     return;
   }
   ShapeRoi roi2 = new ShapeRoi(edm.getRoi());
   if (!(roi instanceof ShapeRoi)) roi = new ShapeRoi(roi);
   ShapeRoi roi1 = (ShapeRoi) roi;
   roi2 = roi2.not(roi1);
   imp.setRoi(roi2);
   bandSize = n;
 }