private String getFilterString() { final StringBuilder filter = new StringBuilder(); if (useOnlySelectedPaths) filter.append("SelectedPathsOnly"); if (restrictByRoi && roi != null && roi.isArea()) filter.append(" OnlyPointsInsideROI"); if (restrictBySWCType) { filter.append(" [ "); for (final int type : selectedSwcTypes) filter.append(Path.getSWCtypeName(type)).append(" "); filter.append("]"); } if (filter.length() == 0) filter.append("None"); return filter.toString(); }
public ImageStatistics getRawStatistics() { if (roi!=null && roi.isArea()) ip.setRoi(roi); else ip.resetRoi(); return ImageStatistics.getStatistics(ip, AREA+MEAN+MODE+MIN_MAX, null); }
public ImageStatistics getRawStatistics() { if (roi!=null && roi.isArea()) ip.setRoi(roi); else ip.resetRoi(); return ImageStatistics.getStatistics(ip, AREA+MEAN+MODE+MIN_MAX, null); }
public int setup(String arg, ImagePlus imp) { this.arg = arg; this.imp = imp; if (imp!=null) { Roi roi = imp.getRoi(); if (roi!=null && !roi.isArea()) imp.deleteRoi(); // ignore any line selection } int flags = IJ.setupDialog(imp, DOES_ALL-DOES_8C+SUPPORTS_MASKING); if ((flags&PlugInFilter.DOES_STACKS)!=0 && imp.getType()==ImagePlus.GRAY16 && imp.getStackSize()>1 && arg.equals("invert")) { invert16BitStack(imp); return DONE; } return flags; }
public int setup(String arg, ImagePlus imp) { this.arg = arg; this.imp = imp; if (imp!=null) { Roi roi = imp.getRoi(); if (roi!=null && !roi.isArea()) imp.deleteRoi(); // ignore any line selection } int flags = IJ.setupDialog(imp, DOES_ALL-DOES_8C+SUPPORTS_MASKING); if ((flags&PlugInFilter.DOES_STACKS)!=0 && imp.getType()==ImagePlus.GRAY16 && imp.getStackSize()>1 && arg.equals("invert")) { invert16BitStack(imp); return DONE; } return flags; }
/** * Assigns the specified ROI to this image and displays it without saving it * as previousRoi as it is done by <code>setRoi()</code>. */ public void putRoi(Roi newRoi) { Rectangle bounds = new Rectangle(); if (newRoi != null) { // Roi with width and height = 0 is same as null Roi. bounds = newRoi.getBounds(); if (bounds.width == 0 && bounds.height == 0 && newRoi.getType() != Roi.POINT) { newRoi = null; } } roi = newRoi; if (roi != null) { if (ip != null) { ip.setMask(null); if (roi.isArea()) ip.setRoi(bounds); else ip.resetRoi(); } roi.setImage(this); } draw(); }
private void summarizeSkeleton(final SkeletonResult sr) { final String TABLE_TITLE = "Summary of Rendered Paths"; final ResultsTable rt = getTable(TABLE_TITLE); try { double sumLength = 0d; final int[] branches = sr.getBranches(); final double[] avgLengths = sr.getAverageBranchLength(); for (int i = 0; i < sr.getNumOfTrees(); i++) sumLength += avgLengths[i] * branches[i]; rt.incrementCounter(); rt.addValue("N. Rendered Paths", renderingPaths.size()); rt.addValue("Unit", imp.getCalibration().getUnits()); rt.addValue("Total length", sumLength); rt.addValue("Mean branch length", StatUtils.mean(avgLengths)); rt.addValue("Length of longest branch", StatUtils.max(sr.getMaximumBranchLength())); rt.addValue("# Branches", IntStream.of(sr.getBranches()).sum()); rt.addValue("# Junctions", IntStream.of(sr.getJunctions()).sum()); rt.addValue("# End-points", IntStream.of(sr.getEndPoints()).sum()); rt.addValue("Fitering", getFilterString()); if (restrictByRoi && roi != null && roi.isArea()) rt.addValue("ROI Name", roi.getName() == null ? "Unammed ROI" : roi.getName()); } catch (final Exception ignored) { SNT.error("Some statistics could not be calculated."); } finally { rt.show(TABLE_TITLE); } }
void invert(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) {IJ.error("Inverse", "Area selection required"); return;} ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, imp.getWidth(), imp.getHeight())); Undo.setup(Undo.ROI, imp); imp.setRoi(s1.xor(s2)); }
void invert(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) {IJ.error("Inverse", "Area selection required"); return;} ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, imp.getWidth(), imp.getHeight())); Undo.setup(Undo.ROI, imp); imp.setRoi(s1.xor(s2)); }
void areaToLine(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) { IJ.error("Area to Line", "Area selection required"); return; } Undo.setup(Undo.ROI, imp); Polygon p = roi.getPolygon(); if (p==null) return; int type1 = roi.getType(); if (type1==Roi.COMPOSITE) { IJ.error("Area to Line", "Composite selections cannot be converted to lines."); return; } int type2 = Roi.POLYLINE; if (type1==Roi.OVAL||type1==Roi.FREEROI||type1==Roi.TRACED_ROI ||((roi instanceof PolygonRoi)&&((PolygonRoi)roi).isSplineFit())) type2 = Roi.FREELINE; Roi roi2 = new PolygonRoi(p.xpoints, p.ypoints, p.npoints, type2); transferProperties(roi, roi2); imp.setRoi(roi2); }
/** Fills outside an Roi. */ public void fillOutside(Roi roi) { if (roi==null || !roi.isArea()) return; ImageProcessor m = getMask(); Rectangle r = getRoi(); ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, width, height)); setRoi(s1.xor(s2)); fill(getMask()); setMask(m); setRoi(r); }
void areaToLine(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) { IJ.error("Area to Line", "Area selection required"); return; } Undo.setup(Undo.ROI, imp); Polygon p = roi.getPolygon(); if (p==null) return; int type1 = roi.getType(); if (type1==Roi.COMPOSITE) { IJ.error("Area to Line", "Composite selections cannot be converted to lines."); return; } int type2 = Roi.POLYLINE; if (type1==Roi.OVAL||type1==Roi.FREEROI||type1==Roi.TRACED_ROI ||((roi instanceof PolygonRoi)&&((PolygonRoi)roi).isSplineFit())) type2 = Roi.FREELINE; Roi roi2 = new PolygonRoi(p.xpoints, p.ypoints, p.npoints, type2); transferProperties(roi, roi2); imp.setRoi(roi2); }
/** Fills outside an Roi. */ public void fillOutside(Roi roi) { if (roi==null || !roi.isArea()) return; ImageProcessor m = getMask(); Rectangle r = getRoi(); ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, width, height)); setRoi(s1.xor(s2)); fill(getMask()); setMask(m); setRoi(r); }
/** prepare an ImageProcessor by setting roi and CalibrationTable. */ private void prepareProcessor(ImageProcessor ip, ImagePlus imp) { ImageProcessor mask = imp.getMask(); Roi roi = imp.getRoi(); if (roi!=null && roi.isArea()) ip.setRoi(roi); else ip.setRoi((Roi)null); if (imp.getStackSize()>1) { ImageProcessor ip2 = imp.getProcessor(); double min1 = ip2.getMinThreshold(); double max1 = ip2.getMaxThreshold(); double min2 = ip.getMinThreshold(); double max2 = ip.getMaxThreshold(); if (min1!=ImageProcessor.NO_THRESHOLD && (min1!=min2||max1!=max2)) ip.setThreshold(min1, max1, ImageProcessor.NO_LUT_UPDATE); } //float[] cTable = imp.getCalibration().getCTable(); //ip.setCalibrationTable(cTable); }
/** prepare an ImageProcessor by setting roi and CalibrationTable. */ private void prepareProcessor(ImageProcessor ip, ImagePlus imp) { ImageProcessor mask = imp.getMask(); Roi roi = imp.getRoi(); if (roi!=null && roi.isArea()) ip.setRoi(roi); else ip.setRoi((Roi)null); if (imp.getStackSize()>1) { ImageProcessor ip2 = imp.getProcessor(); double min1 = ip2.getMinThreshold(); double max1 = ip2.getMaxThreshold(); double min2 = ip.getMinThreshold(); double max2 = ip.getMaxThreshold(); if (min1!=ImageProcessor.NO_THRESHOLD && (min1!=min2||max1!=max2)) ip.setThreshold(min1, max1, ImageProcessor.NO_LUT_UPDATE); } //float[] cTable = imp.getCalibration().getCTable(); //ip.setCalibrationTable(cTable); }
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."); }
/** Returns an ImageStatistics object generated using the specified measurement options, histogram bin count and histogram range. */ public ImageStatistics getStatistics(int mOptions, int nBins, double histMin, double histMax) { ImageProcessor ip2 = ip; int bitDepth = getBitDepth(); if (nBins!=256 && (bitDepth==8||bitDepth==24)) ip2 =ip.convertToShort(false); if (roi!=null && roi.isArea()) ip2.setRoi(roi); else ip2.resetRoi(); ip2.setHistogramSize(nBins); Calibration cal = getCalibration(); if (getType()==GRAY16&& !(histMin==0.0&&histMax==0.0)) { histMin = cal.getRawValue(histMin); histMax=cal.getRawValue(histMax); } ip2.setHistogramRange(histMin, histMax); ImageStatistics stats = ImageStatistics.getStatistics(ip2, mOptions, cal); ip2.setHistogramSize(256); ip2.setHistogramRange(0.0, 0.0); return stats; }
/** Returns an ImageStatistics object generated using the specified measurement options, histogram bin count and histogram range. */ public ImageStatistics getStatistics(int mOptions, int nBins, double histMin, double histMax) { ImageProcessor ip2 = ip; int bitDepth = getBitDepth(); if (nBins!=256 && (bitDepth==8||bitDepth==24)) ip2 =ip.convertToShort(false); if (roi!=null && roi.isArea()) ip2.setRoi(roi); else ip2.resetRoi(); ip2.setHistogramSize(nBins); Calibration cal = getCalibration(); if (getType()==GRAY16&& !(histMin==0.0&&histMax==0.0)) { histMin = cal.getRawValue(histMin); histMax=cal.getRawValue(histMax); } ip2.setHistogramRange(histMin, histMax); ImageStatistics stats = ImageStatistics.getStatistics(ip2, mOptions, cal); ip2.setHistogramSize(256); ip2.setHistogramRange(0.0, 0.0); return stats; }
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."); }
/** Returns a reference to the current ImageProcessor. If there is no ImageProcessor, it creates one. Returns null if this ImagePlus contains no ImageProcessor and no AWT Image. Sets the line width to the current line width and sets the calibration table if the image is density calibrated. */ public ImageProcessor getProcessor() { if (ip==null) return null; if (roi!=null && roi.isArea()) ip.setRoi(roi.getBounds()); else ip.resetRoi(); if (!compositeImage) ip.setLineWidth(Line.getWidth()); if (ij!=null) ip.setProgressBar(ij.getProgressBar()); Calibration cal = getCalibration(); if (cal.calibrated()) ip.setCalibrationTable(cal.getCTable()); else ip.setCalibrationTable(null); if (Recorder.record) { Recorder recorder = Recorder.getInstance(); if (recorder!=null) recorder.imageUpdated(this); } return ip; }