Refine search
protected void apply() { Roi roi = image.getRoi(); if (roi == null) return; ImageProcessor ip = image.getProcessor(); apply(ip, roi, minThreshold, maxThreshold, erodeDilateIterations, showBinary); }
/** * Draws the histogram using the specified title, number of bins and * histogram range. Currently, the number of bins must be 256 and the * histogram range range must be the same as the image range expect for 32 * bit images. */ public void showHistogram(ImagePlus imp, int bins, double histMin, double histMax) { boolean limitToThreshold = (Analyzer.getMeasurements() & LIMIT) != 0; if(channel != INTENSITY && imp.getType() == ImagePlus.COLOR_RGB) { ColorProcessor cp = (ColorProcessor) imp.getProcessor(); ImageProcessor ip = cp.toFloat(channel, null); ImagePlus imp2 = new ImagePlus("", ip); imp2.setRoi(imp.getRoi()); stats = imp2.getStatistics(AREA + MEAN + MODE + MIN_MAX, bins, histMin, histMax); } else { stats = imp.getStatistics(AREA + MEAN + MODE + MIN_MAX + (limitToThreshold ? LIMIT : 0), bins, histMin, histMax); } showHistogram(imp, stats); }
@Override public void sliceChanged(ImagePlus image) { // image.setRoi(Cell_Finder.makeShapeRoi(Cell_Finder.getRois(image.getProcessor(), 20, 7, 6))); Roi[] rois = getRois(image); int previousCurrentSlice = latestCurrentSlice.get(image).intValue(); int currentSlice = image.getCurrentSlice(); latestCurrentSlice.put(image, new Integer(currentSlice)); rois[previousCurrentSlice - 1] = image.getRoi(); if (rois[previousCurrentSlice - 1] != null && rois[currentSlice - 1] == null) { int step = currentSlice > previousCurrentSlice ? 1 : -1; for (int i = previousCurrentSlice; i != currentSlice + step; i += step) if (rois[i - 1] == null) rois[i - 1] = optimizeRoi(rois[i - 1 - step], image.getProcessor()); } setRoi(image, rois[currentSlice - 1]); }
void createEllipse(ImagePlus imp) { IJ.showStatus("Fitting ellipse"); Roi roi = imp.getRoi(); if (roi==null) {noRoi("Fit Ellipse"); return;} if (roi.isLine()) {IJ.error("Fit Ellipse", "\"Fit Ellipse\" does not work with line selections"); return;} ImageProcessor ip = imp.getProcessor(); ip.setRoi(roi); int options = Measurements.CENTROID+Measurements.ELLIPSE; ImageStatistics stats = ImageStatistics.getStatistics(ip, options, null); double dx = stats.major*Math.cos(stats.angle/180.0*Math.PI)/2.0; double dy = - stats.major*Math.sin(stats.angle/180.0*Math.PI)/2.0; double x1 = stats.xCentroid - dx; double x2 = stats.xCentroid + dx; double y1 = stats.yCentroid - dy; double y2 = stats.yCentroid + dy; double aspectRatio = stats.minor/stats.major; Undo.setup(Undo.ROI, imp); imp.deleteRoi(); Roi roi2 = new EllipseRoi(x1,y1,x2,y2,aspectRatio); transferProperties(roi, roi2); imp.setRoi(roi2); }
public static void setAutoThreshold(ImagePlus imp, String method) { ImageProcessor ip = imp.getProcessor(); if (ip instanceof ColorProcessor) throw new IllegalArgumentException("Non-RGB image required"); ip.setRoi(imp.getRoi()); if (method!=null) { try { if (method.indexOf("stack")!=-1) setStackThreshold(imp, ip, method); else ip.setAutoThreshold(method); } catch (Exception e) { log(e.getMessage()); } } else ip.setAutoThreshold(ImageProcessor.ISODATA2, ImageProcessor.RED_LUT); imp.updateAndDraw(); }
/** Draws the histogram using the specified title, number of bins and histogram range. Currently, the number of bins must be 256 and the histogram range range must be the same as the image range expect for 32 bit images. */ public void showHistogram(ImagePlus imp, int bins, double histMin, double histMax) { boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; ImageProcessor ip = imp.getProcessor(); if (ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD && ip.getLutUpdateMode()==ImageProcessor.NO_LUT_UPDATE) limitToThreshold = false; // ignore invisible thresholds if (imp.getBitDepth()==24 && rgbMode<INTENSITY1) rgbMode=INTENSITY1; if (rgbMode==RED||rgbMode==GREEN||rgbMode==BLUE) { int channel = rgbMode - 2; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); ip = cp.getChannel(channel, null); ImagePlus imp2 = new ImagePlus("", ip); imp2.setRoi(imp.getRoi()); stats = imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); } else if (rgbMode==RGB) stats = RGBHistogram(imp, bins, histMin, histMax); else stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX+(limitToThreshold?LIMIT:0), bins, histMin, histMax); showHistogram(imp, stats); }
public static void setAutoThreshold(ImagePlus imp, String method) { ImageProcessor ip = imp.getProcessor(); if (ip instanceof ColorProcessor) throw new IllegalArgumentException("Non-RGB image required"); ip.setRoi(imp.getRoi()); if (method!=null) { try { if (method.indexOf("stack")!=-1) setStackThreshold(imp, ip, method); else ip.setAutoThreshold(method); } catch (Exception e) { log(e.getMessage()); } } else ip.setAutoThreshold(ImageProcessor.ISODATA2, ImageProcessor.RED_LUT); imp.updateAndDraw(); }
void showInternalClipboard() { ImagePlus clipboard = ImagePlus.getClipboard(); if (clipboard!=null) { ImageProcessor ip = clipboard.getProcessor(); ImagePlus imp2 = new ImagePlus("Clipboard", ip.duplicate()); Roi roi = clipboard.getRoi(); imp2.deleteRoi(); if (roi!=null && roi.isArea() && roi.getType()!=Roi.RECTANGLE) { roi = (Roi)roi.clone(); roi.setLocation(0, 0); imp2.setRoi(roi); IJ.run(imp2, "Clear Outside", null); imp2.deleteRoi(); } WindowManager.checkForDuplicateName = true; imp2.show(); } else IJ.error("The internal clipboard is empty."); }
public int setup(String arg, ImagePlus imp) { this.imp = imp; mainThread = Thread.currentThread(); if (imp==null) {IJ.noImage(); return DONE;} if (arg.equals("final")&&imp.getRoi()==null) { imp.getProcessor().resetMinAndMax(); imp.updateAndDraw(); return DONE; } IJ.resetEscape(); Roi roi = imp.getRoi(); isLineRoi= roi!=null && roi.isLine(); nSlices = imp.getStackSize(); if (imp.getStackSize()==1) flags |= PARALLELIZE_IMAGES; else flags |= PARALLELIZE_STACKS; imp.startTiming(); return flags; }
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()); }
float[] getZAxisProfile(){ Roi roi = imp.getRoi(); if (roi!=null && roi.isLine()) { IJ.error("ZAxisProfiler", "This command does not work with line selections."); return null; } ImageProcessor ip = imp.getProcessor(); double minThreshold = ip.getMinThreshold(); double maxThreshold = ip.getMaxThreshold(); return getZAxisProfile(roi, minThreshold, maxThreshold); } //Adapted from ImageJ code by Wayne Rasband
protected boolean updateROI(ImagePlus image) { Roi roi = image.getRoi(); if (roi == null || !(roi instanceof PolygonRoi)) { if (constructing && this.roi != null) return true; this.roi = null; return false; } if (this.roi == roi) return true; if (roi instanceof PolygonRoiPublic) this.roi = (PolygonRoiPublic)roi; else { this.roi = new PolygonRoiPublic((PolygonRoi)roi); image.setRoi(roi); roi.setImage(image); } return true; }
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()); }
public int setup(String arg, ImagePlus imp) { this.imp = imp; mainThread = Thread.currentThread(); if (imp==null) {IJ.noImage(); return DONE;} if (arg.equals("final")&&imp.getRoi()==null) { imp.getProcessor().resetMinAndMax(); imp.updateAndDraw(); return DONE; } IJ.resetEscape(); Roi roi = imp.getRoi(); isLineRoi= roi!=null && roi.isLine(); nSlices = imp.getStackSize(); if (imp.getStackSize()==1) flags |= PARALLELIZE_IMAGES; else flags |= PARALLELIZE_STACKS; imp.startTiming(); return flags; }