/** Returns a selection created from the thresholded pixels in the specified image, or null if there are no thresholded pixels. */ public static Roi run(ImagePlus imp) { ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(imp.getProcessor()); }
/** Returns a selection created from the thresholded pixels in the specified image, or null if there are no thresholded pixels. */ public static Roi run(ImagePlus imp) { ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(imp.getProcessor()); }
@Override public Area call() throws Exception { final Image<BitType> imb = interpol.process(weight); final ImagePlus imp = ImageJFunctions.copyToImagePlus(imb, ImagePlus.GRAY8); // BitType gets copied to 0 and 255 in 8-bit ByteProcessor final ThresholdToSelection ts = new ThresholdToSelection(); ts.setup("", imp); final ImageProcessor ip = imp.getProcessor(); ip.setThreshold(1, 255, ImageProcessor.NO_LUT_UPDATE); ts.run(ip); final Roi roi = imp.getRoi(); return null == roi ? new Area() : M.getArea(roi).createTransformedArea(back); } }));
void createSelection() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) return; int saveMode = mode; mode = BLACK_AND_WHITE; apply(imp); mode = saveMode; ImageProcessor ip = imp.getProcessor().convertToByte(false); int fg = Prefs.blackBackground?255:0; ip.setThreshold(fg, fg, ImageProcessor.NO_LUT_UPDATE); Roi roi = (new ThresholdToSelection()).convert(ip); reset(imp); imp.setRoi(roi); }
void createSelection() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) return; int saveMode = mode; mode = BLACK_AND_WHITE; apply(imp); mode = saveMode; ImageProcessor ip = imp.getProcessor().convertToByte(false); int fg = Prefs.blackBackground?255:0; ip.setThreshold(fg, fg, ImageProcessor.NO_LUT_UPDATE); Roi roi = (new ThresholdToSelection()).convert(ip); reset(imp); imp.setRoi(roi); }
Roi getRoiNonBackground( ByteProcessor bp ) { bp.setThreshold(1,255,ImageProcessor.NO_LUT_UPDATE); // bp.threshold(0); ImageStack tempStack = new ImageStack(bp.getWidth(),bp.getHeight()); tempStack.addSlice(null,bp); ImagePlus imp = new ImagePlus("example stack",tempStack); ThresholdToSelection tts = new ThresholdToSelection(); tts.setup( "", imp ); tts.run(bp); // imp.show(); return imp.getRoi(); }
void select() { ImageProcessor ip = copy.duplicate(); ImagePlus dummy = new ImagePlus("dummy", ip); byte[] p = (byte[])ip.getPixels(); ThresholdToSelection ts = new ThresholdToSelection(); for (int i = 1; i <= image.getStackSize(); i++) { Roi roi = stackWindow.getRoi(i); if (roi == null) continue; copy = image.getStack().getProcessor(i); Arrays.fill(p, (byte)0); apply(ip, roi, minThreshold, maxThreshold, erodeDilateIterations, true); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ts.setup("", dummy); ts.run(ip); stackWindow.setRoi(i, dummy.getRoi()); } }
Roi convertLineToPolygon(Roi roi, ImageProcessor ip) { if (roi==null) return null; ip.resetRoi(); ip.setColor(0); ip.fill(); ip.setColor(255); if (roi.getType()==Roi.LINE && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); //new ImagePlus("ip", ip.duplicate()).show(); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(ip); }
Roi convertLineToPolygon(Roi roi, ImageProcessor ip) { if (roi==null) return null; ip.resetRoi(); ip.setColor(0); ip.fill(); ip.setColor(255); if (roi.getType()==Roi.LINE && roi.getStrokeWidth()>1) ip.fillPolygon(roi.getPolygon()); else roi.drawPixels(ip); //new ImagePlus("ip", ip.duplicate()).show(); ip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); return tts.convert(ip); }
roi.drawPixels(ip2); ip2.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ThresholdToSelection tts = new ThresholdToSelection(); roi2 = tts.convert(ip2); if (roi2==null)
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); } }
private static Roi shrink(Roi roi, int n) { Rectangle bounds = roi.getBounds(); int width = bounds.width + 2; int height = bounds.height + 2; ImageProcessor ip = new ByteProcessor(width, height); roi.setLocation(1, 1); ip.setColor(255); ip.fill(roi); roi.setLocation(bounds.x, bounds.y); boolean bb = Prefs.blackBackground; Prefs.blackBackground = true; new EDM().toEDM(ip); Prefs.blackBackground = bb; ip.setThreshold(n+1, 255, ImageProcessor.NO_LUT_UPDATE); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2==null) return roi; Rectangle bounds2 = roi2.getBounds(); if (bounds2.width<=0 && bounds2.height<=0) return roi; roi2.setLocation(bounds.x+bounds2.x-1, bounds.y+bounds2.y-1); return roi2; }
private static Roi shrink(Roi roi, int n) { Rectangle bounds = roi.getBounds(); int width = bounds.width + 2; int height = bounds.height + 2; ImageProcessor ip = new ByteProcessor(width, height); roi.setLocation(1, 1); ip.setColor(255); ip.fill(roi); roi.setLocation(bounds.x, bounds.y); boolean bb = Prefs.blackBackground; Prefs.blackBackground = true; new EDM().toEDM(ip); Prefs.blackBackground = bb; ip.setThreshold(n+1, 255, ImageProcessor.NO_LUT_UPDATE); Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2==null) return roi; Rectangle bounds2 = roi2.getBounds(); if (bounds2.width<=0 && bounds2.height<=0) return roi; roi2.setLocation(bounds.x+bounds2.x-1, bounds.y+bounds2.y-1); return roi2; }
Roi roi2 = (new ThresholdToSelection()).convert(ip); if (roi2==null) return roi;
public void processOpenButton() { // Convert to mask ImagePlus image = cc.getImage(); ImageProcessor ip = image.getProcessor(); ImageProcessor newip = new ByteProcessor( ip.getWidth(), ip.getHeight()); newip.setBackgroundValue(0); newip.setRoi(image.getRoi()); newip.setValue(255); newip.fill(newip.getMask()); // open newip.erode(); newip.dilate(); // convert back to selection newip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ImagePlus tmp = new ImagePlus(" ", newip); ThresholdToSelection ts = new ThresholdToSelection(); ts.setup("", tmp); ts.run(newip); newip.resetThreshold(); image.setRoi(tmp.getRoi()); }
public void processCloseButton() { // Convert to mask ImagePlus image = cc.getImage(); ImageProcessor ip = image.getProcessor(); ImageProcessor newip = new ByteProcessor( ip.getWidth(), ip.getHeight()); newip.setBackgroundValue(0); newip.setRoi(image.getRoi()); newip.setValue(255); newip.fill(newip.getMask()); // open newip.dilate(); newip.erode(); // convert back to selection newip.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); ImagePlus tmp = new ImagePlus(" ", newip); ThresholdToSelection ts = new ThresholdToSelection(); ts.setup("", tmp); ts.run(newip); newip.resetThreshold(); image.setRoi(tmp.getRoi()); }
ImagePlus roiImage = new ImagePlus("bla", stack); ThresholdToSelection ts = new ThresholdToSelection(); ts.setup("", roiImage); for(int i = firstIndex; i <= lastIndex; i++) {
ImagePlus roiImage = new ImagePlus("bla", stack); ThresholdToSelection ts = new ThresholdToSelection(); ts.setup("", roiImage); for(int i = firstIndex; i <= lastIndex; i++) {
mask.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); double xbase=roi.getXBase(), ybase=roi.getYBase(); Roi roi2 = new ThresholdToSelection().convert(mask); if (roi2!=null && (roi2 instanceof ShapeRoi)) { double perim = roi.getLength();