void loadTransformation(String filename, ResultsTable res) { try { String line; FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); if (!br.readLine().equals(" Z-Step Raw Width minus Heigh Calibration Width minus Height")) { IJ.error("File does not seam to be an Astigmatism calibration file"); return; } // java.lang.String [] elements = new java.lang.String [3]; java.lang.String[] elements; int counter = 1; res.reset(); while ((line = br.readLine()) != null) { IJ.showStatus("Loading element " + counter + "... sit back and relax."); counter++; line.trim(); elements = line.split("\t"); res.incrementCounter(); res.addValue("Z-Step", Double.parseDouble(elements[1])); res.addValue("Raw Width minus Heigh", Double.parseDouble(elements[2])); res.addValue("Calibration Width minus Height", Double.parseDouble(elements[3])); } fr.close(); } catch (FileNotFoundException e) { IJ.error("File not found exception" + e); return; } catch (IOException e) { IJ.error("IOException exception" + e); return; } catch (NumberFormatException e) { IJ.error("Number format exception" + e); return; } }
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(); }
void addToRoiManager(ImagePlus imp) { if (IJ.macroRunning() && Interpreter.isBatchModeRoiManager()) IJ.error("run(\"Add to Manager\") may not work in batch mode macros"); Frame frame = WindowManager.getFrame("ROI Manager"); if (frame == null) IJ.run("ROI Manager..."); if (imp == null) return; Roi roi = imp.getRoi(); if (roi == null) return; frame = WindowManager.getFrame("ROI Manager"); if (frame == null || !(frame instanceof RoiManager)) IJ.error("ROI Manager not found"); RoiManager rm = (RoiManager) frame; boolean altDown = IJ.altKeyDown(); IJ.setKeyUp(IJ.ALL_KEYS); if (altDown && !IJ.macroRunning()) IJ.setKeyDown(KeyEvent.VK_SHIFT); if (roi.getState() == Roi.CONSTRUCTING) { // wait (up to 2 sec.) until ROI finished long start = System.currentTimeMillis(); while (true) { IJ.wait(10); if (roi.getState() != Roi.CONSTRUCTING) break; if ((System.currentTimeMillis() - start) > 2000) { IJ.beep(); IJ.error("Add to Manager", "Selection is not complete"); return; } } } rm.runCommand("add"); IJ.setKeyUp(IJ.ALL_KEYS); }
void fitSpline() { Roi roi = imp.getRoi(); if (roi == null) { IJ.error("Spline", "Selection required"); return; } int type = roi.getType(); boolean segmentedSelection = type == Roi.POLYGON || type == Roi.POLYLINE; if (!(segmentedSelection || type == Roi.FREEROI || type == Roi.TRACED_ROI || type == Roi.FREELINE)) { IJ.error("Spline", "Polygon or polyline selection required"); return; } if (roi instanceof EllipseRoi) return; PolygonRoi p = (PolygonRoi) roi; if (!segmentedSelection) p = trimPolygon(p, p.getUncalibratedLength()); String options = Macro.getOptions(); if (options != null && options.indexOf("straighten") != -1) p.fitSplineForStraightening(); else if (options != null && options.indexOf("remove") != -1) p.removeSplineFit(); else p.fitSpline(); imp.draw(); LineWidthAdjuster.update(); }
public boolean beadCalibration3d() { imp = IJ.getImage(); if (imp == null) { IJ.noImage(); return false; } else if (imp.getStackSize() == 1) { IJ.error("Stack required"); return false; } else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16) { // In order to support 32bit images, pict[] must be changed to float[], and getPixel(x, y); // requires a Float.intBitsToFloat() conversion IJ.error("8 or 16 bit greyscale image required"); return false; } width = imp.getWidth(); height = imp.getHeight(); nslices = imp.getStackSize(); imtitle = imp.getTitle(); models[0] = "*None*"; models[1] = "line"; models[2] = "2nd degree polynomial"; models[3] = "3rd degree polynomial"; models[4] = "4th degree polynomial"; GenericDialog gd = new GenericDialog("3D PALM calibration"); gd.addNumericField("Maximum FWHM (in px)", prefs.get("QuickPALM.3Dcal_fwhm", 20), 0); gd.addNumericField( "Particle local threshold (% maximum intensity)", prefs.get("QuickPALM.pthrsh", 20), 0); gd.addNumericField("Z-spacing (nm)", prefs.get("QuickPALM.z-step", 10), 2); gd.addNumericField("Calibration Z-smoothing (radius)", prefs.get("QuickPALM.window", 1), 0); gd.addChoice("Model", models, prefs.get("QuickPALM.model", models[3])); gd.addCheckbox( "Show divergence of bead positions against model", prefs.get("QuickPALM.3Dcal_showDivergence", false)); gd.addCheckbox("Show extra particle info", prefs.get("QuickPALM.3Dcal_showExtraInfo", false)); gd.addMessage("\n\nDon't forget to save the table in the end..."); gd.showDialog(); if (gd.wasCanceled()) return false; fwhm = gd.getNextNumber(); prefs.set("QuickPALM.QuickPALM.3Dcal_fwhm", fwhm); pthrsh = gd.getNextNumber() / 100; prefs.set("QuickPALM.pthrsh", pthrsh * 100); cal_z = gd.getNextNumber(); prefs.set("QuickPALM.z-step", cal_z); window = (int) gd.getNextNumber(); prefs.set("QuickPALM.window", window); model = gd.getNextChoice(); prefs.set("QuickPALM.model", model); part_divergence = gd.getNextBoolean(); prefs.set("QuickPALM.3Dcal_showDivergence", part_divergence); part_extrainfo = gd.getNextBoolean(); prefs.set("QuickPALM.3Dcal_showExtraInfo", part_extrainfo); return true; }
/** Performs actual projection using specified method. */ public void doProjection() { if (imp == null) return; sliceCount = 0; if (method < AVG_METHOD || method > MEDIAN_METHOD) method = AVG_METHOD; for (int slice = startSlice; slice <= stopSlice; slice += increment) sliceCount++; if (method == MEDIAN_METHOD) { projImage = doMedianProjection(); return; } // Create new float processor for projected pixels. FloatProcessor fp = new FloatProcessor(imp.getWidth(), imp.getHeight()); ImageStack stack = imp.getStack(); RayFunction rayFunc = getRayFunction(method, fp); if (IJ.debugMode == true) { IJ.log("\nProjecting stack from: " + startSlice + " to: " + stopSlice); } // Determine type of input image. Explicit determination of // processor type is required for subsequent pixel // manipulation. This approach is more efficient than the // more general use of ImageProcessor's getPixelValue and // putPixel methods. int ptype; if (stack.getProcessor(1) instanceof ByteProcessor) ptype = BYTE_TYPE; else if (stack.getProcessor(1) instanceof ShortProcessor) ptype = SHORT_TYPE; else if (stack.getProcessor(1) instanceof FloatProcessor) ptype = FLOAT_TYPE; else { IJ.error("Z Project", "Non-RGB stack required"); return; } // Do the projection. for (int n = startSlice; n <= stopSlice; n += increment) { IJ.showStatus("ZProjection " + color + ": " + n + "/" + stopSlice); IJ.showProgress(n - startSlice, stopSlice - startSlice); projectSlice(stack.getPixels(n), rayFunc, ptype); } // Finish up projection. if (method == SUM_METHOD) { fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else if (method == SD_METHOD) { rayFunc.postProcess(); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else { rayFunc.postProcess(); projImage = makeOutputImage(imp, fp, ptype); } if (projImage == null) IJ.error("Z Project", "Error computing projection."); }
void loadParticleResults(String filename, ResultsTable res) { try { String line; FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); java.lang.String header = " Intensity X (px) Y (px) X (nm) Y (nm) Z (nm) Left-Width(px) Right-Width (px) Up-Height (px) Down-Height (px) X Symmetry (%) Y Symmetry (%) Width minus Height (px) Frame Number"; java.lang.String firstline = br.readLine(); if (!firstline.contains("X (px) Y (px) X (nm) Y (nm) Z (nm)")) { IJ.error("File does not seam to be a Particles Table file"); IJ.log("Found header: " + firstline); IJ.log("Expecting: " + header); return; } res.reset(); int counter = 1; java.util.concurrent.locks.Lock lock = new java.util.concurrent.locks.ReentrantLock(); ThreadedLoader tloader = new ThreadedLoader(); // java.lang.String txt = fr.read(); while ((line = br.readLine()) != null) { tloader = new ThreadedLoader(); tloader.mysetup(res, lock, line); tloader.start(); IJ.showStatus("Loading particle " + counter + "... sit back and relax."); counter++; } try { tloader.join(); } catch (Exception e) { IJ.error("" + e); } if (res.getCounter() < 5000000) { IJ.showStatus("Creating particle table, this should take a few seconds..."); res.show("Results"); } else IJ.showMessage( "Warning", "Results table has too many particles, they will not be shown but the data still exists within it\nyou can still use all the plugin functionality or save table changes though the 'Save Particle Table' command."); fr.close(); IJ.showStatus("Done loading table..."); } catch (FileNotFoundException e) { IJ.error("File not found exception" + e); return; } catch (IOException e) { IJ.error("IOException exception" + e); return; } catch (NumberFormatException e) { IJ.error("Number format exception" + e); return; } }
public boolean checkBeads() { rmanager = RoiManager.getInstance(); if (IJ.versionLessThan("1.26i")) return false; else if (rmanager == null) { IJ.error("Add bead ROIs to the RoiManager first (select region then press [t])."); return false; } nrois = rmanager.getCount(); if (nrois == 0) { IJ.error("Add bead ROIs to the RoiManager first (select region then press [t])."); return false; } rois = rmanager.getRoisAsArray(); return true; }
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(); }
public int setup(String arg, ImagePlus imp) { this.arg = arg; this.imp = imp; IJ.register(ParticleAnalyzer.class); if (imp == null) { IJ.noImage(); return DONE; } if (imp.getBitDepth() == 24 && !isThresholdedRGB(imp)) { IJ.error( "Particle Analyzer", "RGB images must be thresholded using\n" + "Image>Adjust>Color Threshold."); return DONE; } if (!showDialog()) return DONE; int baseFlags = DOES_ALL + NO_CHANGES + NO_UNDO; int flags = IJ.setupDialog(imp, baseFlags); processStack = (flags & DOES_STACKS) != 0; slice = 0; saveRoi = imp.getRoi(); if (saveRoi != null && saveRoi.getType() != Roi.RECTANGLE && saveRoi.isArea()) polygon = saveRoi.getPolygon(); imp.startTiming(); nextFontSize = defaultFontSize; nextLineWidth = 1; return flags; }
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { if (doOptions) { this.imp = imp; this.pfr = pfr; GenericDialog gd = new GenericDialog("Binary Options"); gd.addNumericField("Iterations (1-" + MAX_ITERATIONS + "):", iterations, 0, 3, ""); gd.addNumericField("Count (1-8):", count, 0, 3, ""); gd.addCheckbox("Black background", Prefs.blackBackground); gd.addCheckbox("Pad edges when eroding", Prefs.padEdges); gd.addChoice("EDM output:", outputTypes, outputTypes[EDM.getOutputType()]); if (imp != null) { gd.addChoice("Do:", operations, operation); gd.addPreviewCheckbox(pfr); gd.addDialogListener(this); previewing = true; } gd.addHelp(IJ.URL + "/docs/menus/process.html#options"); gd.showDialog(); previewing = false; if (gd.wasCanceled()) return DONE; if (imp == null) { // options dialog only, no do/preview dialogItemChanged(gd, null); // read dialog result return DONE; } return operation.equals(NO_OPERATION) ? DONE : IJ.setupDialog(imp, flags); } else { // no dialog, 'arg' is operation type if (!((ByteProcessor) imp.getProcessor()).isBinary()) { IJ.error("8-bit binary (black and white only) image required."); return DONE; } return IJ.setupDialog(imp, flags); } }
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; imp.killRoi(); imp.setRoi(new EllipseRoi(x1, y1, x2, y2, aspectRatio)); }
void runMacro(String arg) { Roi roi = imp.getRoi(); if (IJ.macroRunning()) { String options = Macro.getOptions(); if (options != null && (options.indexOf("grid=") != -1 || options.indexOf("interpolat") != -1)) { IJ.run("Rotate... ", options); // run Image>Transform>Rotate return; } } if (roi == null) { IJ.error("Rotate>Selection", "This command requires a selection"); return; } roi = (Roi) roi.clone(); if (arg.equals("rotate")) { double d = Tools.parseDouble(angle); if (Double.isNaN(d)) angle = "15"; String value = IJ.runMacroFile("ij.jar:RotateSelection", angle); if (value != null) angle = value; } else if (arg.equals("enlarge")) { String value = IJ.runMacroFile("ij.jar:EnlargeSelection", enlarge); if (value != null) enlarge = value; Roi.previousRoi = roi; } }
void addToRoiManager(ImagePlus imp) { if (IJ.macroRunning() && Interpreter.isBatchModeRoiManager()) IJ.error("run(\"Add to Manager\") may not work in batch mode macros"); Frame frame = WindowManager.getFrame("ROI Manager"); if (frame == null) IJ.run("ROI Manager..."); if (imp == null) return; Roi roi = imp.getRoi(); if (roi == null) return; frame = WindowManager.getFrame("ROI Manager"); if (frame == null || !(frame instanceof RoiManager)) IJ.error("ROI Manager not found"); RoiManager rm = (RoiManager) frame; boolean altDown = IJ.altKeyDown(); IJ.setKeyUp(IJ.ALL_KEYS); if (altDown && !IJ.macroRunning()) IJ.setKeyDown(KeyEvent.VK_SHIFT); rm.runCommand("add"); IJ.setKeyUp(IJ.ALL_KEYS); }
boolean setProperties(String title, Roi roi) { Frame f = WindowManager.getFrontWindow(); if (f != null && f.getTitle().indexOf("3D Viewer") != -1) return false; if (roi == null) { IJ.error("This command requires a selection."); return false; } RoiProperties rp = new RoiProperties(title, roi); return rp.showDialog(); }
/*------------------------------------------------------------------*/ public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Cancel")) { cancel = true; } else if (ae.getActionCommand().equals("OK")) { cancel = false; } else { cancel = true; IJ.error("Unexpected button ID"); } setVisible(false); } /* end actionPerformed */
public void run(String arg) { int[] wList = WindowManager.getIDList(); if (wList == null) { IJ.error("No images are open."); return; } double thalf = 0.5; boolean keep; GenericDialog gd = new GenericDialog("Bleach correction"); gd.addNumericField("t½:", thalf, 1); gd.addCheckbox("Keep source stack:", true); gd.showDialog(); if (gd.wasCanceled()) return; long start = System.currentTimeMillis(); thalf = gd.getNextNumber(); keep = gd.getNextBoolean(); if (keep) IJ.run("Duplicate...", "title='Bleach corrected' duplicate"); ImagePlus imp1 = WindowManager.getCurrentImage(); int d1 = imp1.getStackSize(); double v1, v2; int width = imp1.getWidth(); int height = imp1.getHeight(); ImageProcessor ip1, ip2, ip3; int slices = imp1.getStackSize(); ImageStack stack1 = imp1.getStack(); ImageStack stack2 = imp1.getStack(); int currentSlice = imp1.getCurrentSlice(); for (int n = 1; n <= slices; n++) { ip1 = stack1.getProcessor(n); ip3 = stack1.getProcessor(1); ip2 = stack2.getProcessor(n); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { v1 = ip1.getPixelValue(x, y); v2 = ip3.getPixelValue(x, y); // =B8/(EXP(-C$7*A8)) v1 = (v1 / Math.exp(-n * thalf)); ip2.putPixelValue(x, y, v1); } } IJ.showProgress((double) n / slices); IJ.showStatus(n + "/" + slices); } // stack2.show(); imp1.updateAndDraw(); }
void fromRoiManager() { ImagePlus imp = IJ.getImage(); RoiManager rm = RoiManager.getInstance(); if (rm == null) { IJ.error("ROI Manager is not open"); return; } Roi[] rois = rm.getRoisAsArray(); if (rois.length == 0) { IJ.error("ROI Manager is empty"); return; } Overlay overlay = new Overlay(); for (int i = 0; i < rois.length; i++) overlay.add((Roi) rois[i].clone()); imp.setOverlay(overlay); ImageCanvas ic = imp.getCanvas(); if (ic != null) ic.setShowAllROIs(false); rm.setEditMode(imp, false); imp.killRoi(); }
void areaToLine(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi == null || !roi.isArea()) { IJ.error("Area to Line", "Area selection required"); return; } 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); imp.setRoi(roi2); }
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())); imp.setRoi(s1.xor(s2)); }
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { angle = gd.getNextNumber(); // only check for invalid input to "angle", don't care about gridLines if (gd.invalidNumber()) { if (gd.wasOKed()) IJ.error("Angle is invalid."); return false; } gridLines = (int) gd.getNextNumber(); interpolationMethod = gd.getNextChoiceIndex(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); if (canEnlarge) enlarge = gd.getNextBoolean(); return true; }
boolean setThresholdLevels(ImagePlus imp, ImageProcessor ip) { double t1 = ip.getMinThreshold(); double t2 = ip.getMaxThreshold(); boolean invertedLut = imp.isInvertedLut(); boolean byteImage = ip instanceof ByteProcessor; if (ip instanceof ShortProcessor) imageType = SHORT; else if (ip instanceof FloatProcessor) imageType = FLOAT; else imageType = BYTE; if (t1 == ImageProcessor.NO_THRESHOLD) { ImageStatistics stats = imp.getStatistics(); if (imageType != BYTE || (stats.histogram[0] + stats.histogram[255] != stats.pixelCount)) { IJ.error( "Particle Analyzer", "A thresholded image or 8-bit binary image is\n" + "required. Threshold levels can be set using\n" + "the Image->Adjust->Threshold tool."); canceled = true; return false; } boolean threshold255 = invertedLut; if (Prefs.blackBackground) threshold255 = !threshold255; if (threshold255) { level1 = 255; level2 = 255; fillColor = 64; } else { level1 = 0; level2 = 0; fillColor = 192; } } else { level1 = t1; level2 = t2; if (imageType == BYTE) { if (level1 > 0) fillColor = 0; else if (level2 < 255) fillColor = 255; } else if (imageType == SHORT) { if (level1 > 0) fillColor = 0; else if (level2 < 65535) fillColor = 65535; } else if (imageType == FLOAT) fillColor = -Float.MAX_VALUE; else return false; } imageType2 = imageType; if (redirectIP != null) { if (redirectIP instanceof ShortProcessor) imageType2 = SHORT; else if (redirectIP instanceof FloatProcessor) imageType2 = FLOAT; else if (redirectIP instanceof ColorProcessor) imageType2 = RGB; else imageType2 = BYTE; } return true; }
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"); }
void convexHull(ImagePlus imp) { Roi roi = imp.getRoi(); int type = roi != null ? roi.getType() : -1; if (!(type == Roi.FREEROI || type == Roi.TRACED_ROI || type == Roi.POLYGON || type == Roi.POINT)) { IJ.error("Convex Hull", "Polygonal or point selection required"); return; } if (roi instanceof EllipseRoi) return; Polygon p = roi.getConvexHull(); if (p != null) imp.setRoi(new PolygonRoi(p.xpoints, p.ypoints, p.npoints, roi.POLYGON)); }
void addSelection() { ImagePlus imp = IJ.getImage(); String macroOptions = Macro.getOptions(); if (macroOptions != null && IJ.macroRunning() && macroOptions.indexOf("remove") != -1) { imp.setOverlay(null); return; } Roi roi = imp.getRoi(); if (roi == null && imp.getOverlay() != null) { GenericDialog gd = new GenericDialog("No Selection"); gd.addMessage("\"Overlay>Add\" requires a selection."); gd.setInsets(15, 40, 0); gd.addCheckbox("Remove existing overlay", false); gd.showDialog(); if (gd.wasCanceled()) return; if (gd.getNextBoolean()) imp.setOverlay(null); return; } if (roi == null) { IJ.error("This command requires a selection."); return; } roi = (Roi) roi.clone(); if (roi.getStrokeColor() == null) roi.setStrokeColor(Toolbar.getForegroundColor()); int width = Line.getWidth(); Rectangle bounds = roi.getBounds(); boolean tooWide = width > Math.max(bounds.width, bounds.height) / 3.0; if (roi.getStroke() == null && width > 1 && !tooWide) roi.setStrokeWidth(Line.getWidth()); Overlay overlay = imp.getOverlay(); if (overlay != null && overlay.size() > 0 && !roi.isDrawingTool()) { Roi roi2 = overlay.get(overlay.size() - 1); if (roi.getStroke() == null) roi.setStrokeWidth(roi2.getStrokeWidth()); if (roi.getFillColor() == null) roi.setFillColor(roi2.getFillColor()); } boolean points = roi instanceof PointRoi && ((PolygonRoi) roi).getNCoordinates() > 1; if (points) roi.setStrokeColor(Color.red); if (!IJ.altKeyDown() && !(roi instanceof Arrow)) { RoiProperties rp = new RoiProperties("Add to Overlay", roi); if (!rp.showDialog()) return; } String name = roi.getName(); boolean newOverlay = name != null && name.equals("new-overlay"); if (overlay == null || newOverlay) overlay = new Overlay(); overlay.add(roi); imp.setOverlay(overlay); overlay2 = overlay; if (points || (roi instanceof ImageRoi) || (roi instanceof Arrow)) imp.killRoi(); Undo.setup(Undo.OVERLAY_ADDITION, imp); }
public void run(String arg) { ImagePlus imp = IJ.getImage(); int size = imp.getStackSize(); if (size == 1) { IJ.error("Z Project", "This command requires a stack"); return; } if (imp.isHyperStack()) { new ZProjector().run(""); return; } if (!showDialog(imp)) return; ImagePlus imp2 = groupZProject(imp, method, groupSize); if (imp != null) imp2.show(); }
boolean showDialog(ImagePlus imp) { int size = imp.getStackSize(); GenericDialog gd = new GenericDialog("Z Project"); gd.addChoice("Projection method", ZProjector.METHODS, ZProjector.METHODS[method]); gd.addNumericField("Group size:", size, 0); gd.showDialog(); if (gd.wasCanceled()) return false; method = gd.getNextChoiceIndex(); groupSize = (int) gd.getNextNumber(); if (groupSize < 1 || groupSize > size || (size % groupSize) != 0) { IJ.error("ZProject", "Group size must divide evenly into the stack size."); return false; } return true; }
public void run(String arg) { imp = WindowManager.getCurrentImage(); if (imp == null) { IJ.noImage(); return; } ImageStack stack = imp.getStack(); int size = stack.getSize(); if (size == 1 || (imp.getNChannels() == size && imp.isComposite())) { IJ.error("Stack or hyperstack required"); return; } if (!showDialog(stack)) return; if (hyperstack) reduceHyperstack(imp, factor, reduceSlices); else reduceStack(imp, factor); }
private RayFunction getRayFunction(int method, FloatProcessor fp) { switch (method) { case AVG_METHOD: case SUM_METHOD: return new AverageIntensity(fp, sliceCount); case MAX_METHOD: return new MaxIntensity(fp); case MIN_METHOD: return new MinIntensity(fp); case SD_METHOD: return new StandardDeviation(fp, sliceCount); default: IJ.error("Z Project", "Unknown method."); return null; } }
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(); }