boolean isSmaller(Roi r) { ImageProcessor mask = r.getMask(); if (mask==null) return false; mask.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ImageStatistics stats = ImageStatistics.getStatistics(mask, MEAN+LIMIT, null); return stats.area<=width*height; }
boolean isSmaller(Roi r) { ImageProcessor mask = r.getMask(); if (mask==null) return false; mask.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ImageStatistics stats = ImageStatistics.getStatistics(mask, MEAN+LIMIT, null); return stats.area<=width*height; }
/** Returns the coordinates of the pixels inside this ROI as an array of Points. * @see #getContainedFloatPoints() * @see #iterator() */ public Point[] getContainedPoints() { if (isLine()) { FloatPolygon p = getInterpolatedPolygon(); Point[] points = new Point[p.npoints]; for (int i=0; i<p.npoints; i++) points[i] = new Point((int)Math.round(p.xpoints[i]),(int)Math.round(p.ypoints[i])); return points; } ImageProcessor mask = getMask(); Rectangle bounds = getBounds(); ArrayList points = new ArrayList(); for (int y=0; y<bounds.height; y++) { for (int x=0; x<bounds.width; x++) { if (mask==null || mask.getPixel(x,y)!=0) points.add(new Point(this.x+x,this.y+y)); } } return (Point[])points.toArray(new Point[points.size()]); }
/** Returns the coordinates of the pixels inside this ROI as an array of Points. * @see #getContainedFloatPoints() * @see #iterator() */ public Point[] getContainedPoints() { if (isLine()) { FloatPolygon p = getInterpolatedPolygon(); Point[] points = new Point[p.npoints]; for (int i=0; i<p.npoints; i++) points[i] = new Point((int)Math.round(p.xpoints[i]),(int)Math.round(p.ypoints[i])); return points; } ImageProcessor mask = getMask(); Rectangle bounds = getBounds(); ArrayList points = new ArrayList(); for (int y=0; y<bounds.height; y++) { for (int x=0; x<bounds.width; x++) { if (mask==null || mask.getPixel(x,y)!=0) points.add(new Point(this.x+x,this.y+y)); } } return (Point[])points.toArray(new Point[points.size()]); }
RoiPointsIteratorMask() { if (isLine()) { Roi roi2 = Selection.lineToArea(Roi.this); mask = roi2.getMask(); bounds = roi2.getBounds(); xbase = roi2.x; ybase = roi2.y; } else { mask = getMask(); bounds = getBounds(); xbase = Roi.this.x; ybase = Roi.this.y; } n = bounds.width * bounds.height; findNext(0); // sets next }
public RoiStatistics(Roi roi) { Rectangle bounds = roi.getBounds(); ImageProcessor mask = roi.getMask(); if (mask == null) accumulator = new RectangleAccumulator(bounds); else accumulator = new GenericAccumulator(bounds.x, bounds.y, (ByteProcessor)mask); }
RoiPointsIteratorMask() { if (isLine()) { Roi roi2 = Selection.lineToArea(Roi.this); mask = roi2.getMask(); bounds = roi2.getBounds(); xbase = roi2.x; ybase = roi2.y; } else { mask = getMask(); bounds = getBounds(); xbase = Roi.this.x; ybase = Roi.this.y; } n = bounds.width * bounds.height; findNext(0); // sets next }
/** For images with irregular ROIs, returns a byte mask, otherwise, returns * null. Mask pixels have a non-zero value.and the dimensions of the * mask are equal to the width and height of the ROI. * @see ij.ImagePlus#createRoiMask * @see ij.ImagePlus#createThresholdMask */ public ImageProcessor getMask() { if (roi==null) { if (ip!=null) ip.resetRoi(); return null; } ImageProcessor mask = roi.getMask(); if (mask==null) return null; if (ip!=null && roi!=null) { ip.setMask(mask); ip.setRoi(roi.getBounds()); } return mask; }
/** For images with irregular ROIs, returns a byte mask, otherwise, returns * null. Mask pixels have a non-zero value.and the dimensions of the * mask are equal to the width and height of the ROI. * @see ij.ImagePlus#createRoiMask * @see ij.ImagePlus#createThresholdMask */ public ImageProcessor getMask() { if (roi==null) { if (ip!=null) ip.resetRoi(); return null; } ImageProcessor mask = roi.getMask(); if (mask==null) return null; if (ip!=null && roi!=null) { ip.setMask(mask); ip.setRoi(roi.getBounds()); } return mask; }
public ImageProcessor getMask() { ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]); ImageProcessor ip = imp.getProcessor(); Roi roi = getRoi(); if (null == roi) { ip.resetRoi(); return null; } ImageProcessor mask = roi.getMask(); if (null==mask) return null; ip.setMask(mask); ip.setRoi(roi.getBounds()); return mask; }
/** * Make a mask within an image widthxheight for Roi. * All pixels within Roi will be 1, all others 0. * March 2004, update to conform to ImageJ 1.32e and higher, where getMask returns a ByteProcessor. * @param roi the roi. * @param width the width of the mask. * @param height the height of the mask. * @return a float[] containing the mask bytes. */ public static float [] getMask(Roi roi, int width, int height) { ImageProcessor mp = new ByteProcessor(width, height); ImagePlus np = new ImagePlus("mask in getMask", mp); np.setRoi(roi); np.show(); ByteProcessor bmask = (ByteProcessor) roi.getMask(); mp.setColor(1); mp.fill(bmask); // This is the mask. byte [] mask = (byte []) mp.getPixels(); float [] fmask = new float[mask.length]; for (int i = 0; i < mask.length; i++) fmask[i] = (float) (mask[i] & 0xff); return fmask; } /**
/** Returns the coordinates of the pixels inside this ROI as a FloatPolygon. * @see #getContainedPoints() * @see #iterator() */ public FloatPolygon getContainedFloatPoints() { Roi roi2 = this; if (isLine()) { if (getStrokeWidth()<=1) return roi2.getInterpolatedPolygon(); else roi2 = Selection.lineToArea(this); } ImageProcessor mask = roi2.getMask(); Rectangle bounds = roi2.getBounds(); FloatPolygon points = new FloatPolygon(); for (int y=0; y<bounds.height; y++) { for (int x=0; x<bounds.width; x++) { if (mask==null || mask.getPixel(x,y)!=0) points.addPoint((float)(bounds.x+x),(float)(bounds.y+y)); } } return points; }
/** Returns the coordinates of the pixels inside this ROI as a FloatPolygon. * @see #getContainedPoints() * @see #iterator() */ public FloatPolygon getContainedFloatPoints() { Roi roi2 = this; if (isLine()) { if (getStrokeWidth()<=1) return roi2.getInterpolatedPolygon(); else roi2 = Selection.lineToArea(this); } ImageProcessor mask = roi2.getMask(); Rectangle bounds = roi2.getBounds(); FloatPolygon points = new FloatPolygon(); for (int y=0; y<bounds.height; y++) { for (int x=0; x<bounds.width; x++) { if (mask==null || mask.getPixel(x,y)!=0) points.addPoint((float)(bounds.x+x),(float)(bounds.y+y)); } } return points; }
/** Defines a non-rectangular region of interest that will consist of a rectangular ROI and a mask. After processing, call <code>reset(mask)</code> to restore non-masked pixels. Here is an example: <pre> ip.setRoi(new OvalRoi(50, 50, 100, 50)); ip.fill(); ip.reset(ip.getMask()); </pre> The example assumes <code>snapshot()</code> has been called, which is the case for code executed in the <code>run()</code> method of plugins that implement the <code>PlugInFilter</code> interface. @see ij.ImagePlus#getRoi */ public void setRoi(Roi roi) { if (roi==null) resetRoi(); else { if (roi instanceof PointRoi && ((PointRoi)roi).getNCoordinates()==1) { setMask(null); FloatPolygon p = roi.getFloatPolygon(); setRoi((int)p.xpoints[0], (int)p.ypoints[0], 1, 1); } else { setMask(roi.getMask()); setRoi(roi.getBounds()); } } }
/** Defines a non-rectangular region of interest that will consist of a rectangular ROI and a mask. After processing, call <code>reset(mask)</code> to restore non-masked pixels. Here is an example: <pre> ip.setRoi(new OvalRoi(50, 50, 100, 50)); ip.fill(); ip.reset(ip.getMask()); </pre> The example assumes <code>snapshot()</code> has been called, which is the case for code executed in the <code>run()</code> method of plugins that implement the <code>PlugInFilter</code> interface. @see ij.ImagePlus#getRoi */ public void setRoi(Roi roi) { if (roi==null) resetRoi(); else { if (roi instanceof PointRoi && ((PointRoi)roi).getNCoordinates()==1) { setMask(null); FloatPolygon p = roi.getFloatPolygon(); setRoi((int)p.xpoints[0], (int)p.ypoints[0], 1, 1); } else { setMask(roi.getMask()); setRoi(roi.getBounds()); } } }
private FloatProcessor getRoiProcessor(ImagePlus imp, Roi roi, int index) { ImageProcessor ip = imp.getStack().getProcessor(index); ip.setRoi(roi.getBounds()); FloatProcessor fp = subtract(ip.crop().convertToFloatProcessor(), (float) CameraSetupPlugIn.getOffset()); float minVal = VectorMath.min((float[]) fp.getPixels()); if(minVal < 0) { IJ.log("\\Update:Camera base level is set higher than values in the image!"); fp = add(-minVal, fp); } fp.setMask(roi.getMask()); return fp; }
public FloatPolygon getFloatPolygon() { if (cornerDiameter>0) { ImageProcessor ip = getMask(); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2!=null) { roi2.setLocation(x, y); return roi2.getFloatPolygon(); } } if (subPixelResolution() && bounds!=null) { float[] xpoints = new float[4]; float[] ypoints = new float[4]; xpoints[0] = (float)bounds.x; ypoints[0] = (float)bounds.y; xpoints[1] = (float)(bounds.x+bounds.width); ypoints[1] = (float)bounds.y; xpoints[2] = (float)(bounds.x+bounds.width); ypoints[2] = (float)(bounds.y+bounds.height); xpoints[3] = (float)bounds.x; ypoints[3] = (float)(bounds.y+bounds.height); return new FloatPolygon(xpoints, ypoints); } else { Polygon p = getPolygon(); return new FloatPolygon(toFloat(p.xpoints), toFloat(p.ypoints), p.npoints); } }
public FloatPolygon getFloatPolygon() { if (cornerDiameter>0) { ImageProcessor ip = getMask(); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2!=null) { roi2.setLocation(x, y); return roi2.getFloatPolygon(); } } if (subPixelResolution() && bounds!=null) { float[] xpoints = new float[4]; float[] ypoints = new float[4]; xpoints[0] = (float)bounds.x; ypoints[0] = (float)bounds.y; xpoints[1] = (float)(bounds.x+bounds.width); ypoints[1] = (float)bounds.y; xpoints[2] = (float)(bounds.x+bounds.width); ypoints[2] = (float)(bounds.y+bounds.height); xpoints[3] = (float)bounds.x; ypoints[3] = (float)(bounds.y+bounds.height); return new FloatPolygon(xpoints, ypoints); } else { Polygon p = getPolygon(); return new FloatPolygon(toFloat(p.xpoints), toFloat(p.ypoints), p.npoints); } }
@Override public void run(int i) { //fit elliptic Gaussians ImageProcessor ip = stack.getProcessor(i); ip.setRoi(roi.getBounds()); FloatProcessor fp = (FloatProcessor) ip.crop().convertToFloat(); fp.setMask(roi.getMask()); Thresholder.setCurrentImage(fp); List<Molecule> fits = estimator.getThreadLocalImplementation().estimateParameters(fp, Point.applyRoiMask(roi, detector.getThreadLocalImplementation().detectMoleculeCandidates(filter.getThreadLocalImplementation().filterImage(fp)))); framesProcessed.incrementAndGet(); for(Molecule fit : fits) { fit.insertParamAt(0, MoleculeDescriptor.LABEL_FRAME, MoleculeDescriptor.Units.UNITLESS, i); separator.add(fit); if (showResultsTable) { IJResultsTable.getResultsTable().addRow(fit); } } IJ.showProgress(0.45 + 0.45 * (double) framesProcessed.intValue() / (double) stack.getSize()); IJ.showStatus("Fitting " + LABEL_SIGMA1 + " and " + LABEL_SIGMA2 + ": frame " + framesProcessed + " of " + stack.getSize() + "..."); } });
private void saveSelectionCoordinates(ImagePlus imp) { SaveDialog sd = new SaveDialog("Save Coordinates as Text...", imp.getTitle(), ".csv"); String name = sd.getFileName(); if (name == null) return; String dir = sd.getDirectory(); Roi roi = imp.getRoi(); ImageProcessor ip = imp.getProcessor(); ImageProcessor mask = roi.getMask(); Rectangle r = roi.getBounds(); ResultsTable rt = new ResultsTable(); boolean rgb = imp.getBitDepth()==24; for (int y=0; y<r.height; y++) { for (int x=0; x<r.width; x++) { if (mask==null || mask.getPixel(x,y)!=0) { rt.incrementCounter(); rt.addValue("X", r.x+x); rt.addValue("Y", r.y+y); if (rgb) { int c = ip.getPixel(r.x+x,r.y+y); rt.addValue("Red", (c&0xff0000)>>16); rt.addValue("Green", (c&0xff00)>>8); rt.addValue("Blue", c&0xff); } else rt.addValue("Value", ip.getPixelValue(r.x+x,r.y+y)); } } } rt.save(dir+name); }