// for segmented lines, not polygons public static double[] getSectors(float[] xxf, float[] yyf, double rad) { int len = xxf.length; double[] xx = new double[len]; double[] yy = new double[len]; for (int jj = 0; jj < xxf.length; jj++) { xx[jj] = xxf[jj]; yy[jj] = yyf[jj]; } double pi = Math.PI; double[] vAngles = getVertexAngles(xx, yy); double[] segAngles = getSegmentAngles(xx, yy); double phiSym, phiArc, phi; double dx, dy; // , px, py; for (int jj = 1; jj < len - 1; jj++) { phiSym = (segAngles[jj - 1] + segAngles[jj]) / 2; phiArc = 180 - vAngles[jj]; int nPoints = 3; float[] arcPointsX = new float[nPoints + 1]; float[] arcPointsY = new float[nPoints + 1]; for (int pt = 0; pt < nPoints; pt++) { phi = phiSym - phiArc / 2 + pt * phiArc / (nPoints - 1); dx = rad * Math.cos(phi / 180 * pi); dy = rad * -Math.sin(phi / 180 * pi); arcPointsX[pt] = (float) (xx[jj] + dx); arcPointsY[pt] = (float) (yy[jj] + dy); } arcPointsX[nPoints] = (float) (xx[jj]); arcPointsY[nPoints] = (float) (yy[jj]); PolygonRoi polygon = new PolygonRoi(arcPointsX, arcPointsY, nPoints + 1, Roi.POLYGON); IJ.getImage().setRoi(polygon, true); } return null; }
public static void main(String args[]) { // new ImageJ(); IJ.open("/Applications/ImageJ/Bilder/Bear.jpg"); // IJ.open("Z:/Pictures/Beispielbilder/orchid.jpg"); GRDM_U2 pw = new GRDM_U2(); pw.imp = IJ.getImage(); pw.run(""); }
void hide() { ImagePlus imp = IJ.getImage(); Overlay overlay = imp.getOverlay(); if (overlay != null) { overlay2 = overlay; imp.setOverlay(null); } RoiManager rm = RoiManager.getInstance(); if (rm != null) rm.runCommand("show none"); }
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; }
@Override public String commandExecuting(String command) { if (command.equalsIgnoreCase("Quit") && frame_ != null) { try { if (!frame_.closeSequence(true)) { return null; } } catch (Exception ex) { // do nothing, just make sure to continue quitting } return command; } else if (command.equals("Crop")) { if (IJ.getImage().getStack() instanceof AcquisitionVirtualStack) { new Duplicator().run(IJ.getImage()).show(); // abort further processing of the Crop command return null; } } else if (command.equals("Add Noise")) { // blanket method to make sure that ImageJ filters do not execute on disk-cached images // this may backfire! if (IJ.getImage().getStack() instanceof AcquisitionVirtualStack) { AcquisitionVirtualStack avs = (AcquisitionVirtualStack) IJ.getImage().getStack(); if (avs.getVirtualAcquisitionDisplay().isDiskCached()) { // duplicate the image and then run the ImageJ command on what is now the new image new Duplicator().run(IJ.getImage()).show(); } else { // Image is not disk chached. Warn that data will be lost if (!IJ.showMessageWithCancel( "Micro-Manager data not saved", "Data are not saved and Undo is impossible. \n" + "Do you really want to execute the command?")) { return null; } } } } return command; }
@Override public void run(final String arg) { imp = IJ.getImage(); if (imp == null) { IJ.error("No image open."); return; } if (!setup(imp)) return; run(imp, width, height, minLambda, minPhi, hfov, vfov); }
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(); }
public void run(String arg) { imp = IJ.getImage(); Roi roi = imp.getRoi(); if (roi != null && !roi.isArea()) imp.killRoi(); // ignore any line selection ImageProcessor ip = imp.getProcessor(); if (!showDialog(ip)) return; if (ip.getWidth() > 1 && ip.getHeight() > 1) ip.setInterpolate(interpolate); else ip.setInterpolate(false); ip.setBackgroundValue(bgValue); imp.startTiming(); try { if (newWindow && imp.getStackSize() > 1 && processStack) createNewStack(imp, ip); else scale(ip); } catch (OutOfMemoryError o) { IJ.outOfMemory("Scale"); } IJ.showProgress(1.0); }
@Override public void run(String arg) { ImagePlus imp = IJ.getImage(); GenericDialog gd = new GenericDialog(name); gd.addMessage("Requires SI raw data in OMX (CPZAT) order."); gd.addNumericField("angles", angles, 0); gd.addNumericField("phases", phases, 0); gd.showDialog(); if (gd.wasCanceled()) return; if (gd.wasOKed()) { angles = (int) gd.getNextNumber(); phases = (int) gd.getNextNumber(); } if (!I1l.stackDivisibleBy(imp, phases * angles)) { IJ.showMessage(name, "Error: stack size not consistent with phases/angles."); return; } results = exec(imp); results.report(); }
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(); }
public static void main(String[] args) { String mriImage = args[0]; String outImage = args[1]; String segArgs = args[2]; String outTable = args[3]; String pdxArgs = args[4]; System.out.println("Open: " + mriImage); IJ.open(mriImage); COPD_LungSegment tjPlug = new COPD_LungSegment(); ImagePlus cImage = IJ.getImage(); tjPlug.setup(segArgs, cImage); tjPlug.run(cImage.getProcessor()); IJ.save(cImage, outImage); COPD_PDxLAAx pdxPlug = new COPD_PDxLAAx(); pdxPlug.setup("", cImage); pdxPlug.run(cImage.getProcessor()); ResultsTable rt = Analyzer.getResultsTable(); try { rt.saveAs(outTable); } catch (IOException e) { e.printStackTrace(); } System.out.println("Results Table\n"); String prefix = "rtout, "; for (int i = 0; i < ResultsTable.MAX_COLUMNS; i++) { if (!rt.columnExists(i)) break; String tempOut = rt.getColumnHeading(i); for (double d : rt.getColumnAsDoubles(i)) { tempOut += ", " + d; } System.out.println(prefix + tempOut); } }
void toRoiManager() { ImagePlus imp = IJ.getImage(); Overlay overlay = imp.getOverlay(); if (overlay == null) { IJ.error("Overlay required"); return; } RoiManager rm = RoiManager.getInstance(); if (rm == null) { if (Macro.getOptions() != null && Interpreter.isBatchMode()) rm = Interpreter.getBatchModeRoiManager(); if (rm == null) { Frame frame = WindowManager.getFrame("ROI Manager"); if (frame == null) IJ.run("ROI Manager..."); frame = WindowManager.getFrame("ROI Manager"); if (frame == null || !(frame instanceof RoiManager)) return; rm = (RoiManager) frame; } } rm.runCommand("reset"); for (int i = 0; i < overlay.size(); i++) rm.add(imp, overlay.get(i), i); rm.setEditMode(imp, true); if (rm.getCount() == overlay.size()) imp.setOverlay(null); }
public void run(String arg) { imp = IJ.getImage(); if (imp == null) return; stackSize = imp.getStackSize(); Roi roi = imp.getRoi(); Calibration cal = imp.getCalibration(); if (roi != null && roi.getBounds().equals(prevRoi) && cal.pixelWidth == prevPixelWidth) roi = null; if (roi != null) { boolean rectOrOval = roi != null && (roi.getType() == Roi.RECTANGLE || roi.getType() == Roi.OVAL); oval = rectOrOval && (roi.getType() == Roi.OVAL); // Handle existing oval ROI Rectangle r = roi.getBounds(); width = r.width; height = r.height; xRoi = r.x; yRoi = r.y; if (scaledUnits && cal.scaled()) { xRoi = xRoi * cal.pixelWidth; yRoi = yRoi * cal.pixelHeight; width = width * cal.pixelWidth; height = height * cal.pixelHeight; } if (centered) { // Make xRoi and yRoi consistent when centered mode is active xRoi += width / 2.0; yRoi += height / 2.0; } } else if (!validDialogValues()) { width = imp.getWidth() / 2; height = imp.getHeight() / 2; xRoi = width / 2; yRoi = height / 2; } iSlice = imp.getCurrentSlice(); showDialog(); }
void flatten() { ImagePlus imp = IJ.getImage(); ImagePlus imp2 = imp.flatten(); imp2.setTitle(WindowManager.getUniqueName(imp.getTitle())); imp2.show(); }
void show() { ImagePlus imp = IJ.getImage(); if (overlay2 != null) imp.setOverlay(overlay2); RoiManager rm = RoiManager.getInstance(); if (rm != null) rm.runCommand("show all"); }
// TODO split run method into more sensible methods public void run(final String arg) { if (!ImageCheck.checkEnvironment()) return; final ImagePlus imp = IJ.getImage(); if (null == imp) { IJ.noImage(); return; } final ImageCheck ic = new ImageCheck(); if (!ImageCheck.isBinary(imp)) { IJ.showMessage("Fractal Count requires a binary image."); return; } if (noGo) return; final ImagePlus surfaceImp = findSurfaceVoxels(imp); try { // Fetch data final int width = imp.getWidth(); final int height = imp.getHeight(); final int depth = imp.getStackSize(); if (autoParam) { maxBox = Math.max(width, Math.max(height, depth)) / autoDiv; if (verboseOutput) { IJ.log("Automatic max box size " + maxBox + " selected"); } } // Create variables we need and set them long bestCount; // keep track of best count so far long count = 0; // current count final ArrayList<Double> xList = new ArrayList<Double>(); final ArrayList<Double> yList = new ArrayList<Double>(); int xPos, yPos, zPos, yPart; int xGrid, yGrid, zGrid; int xStart, yStart, zStart; int xEnd, yEnd, zEnd; // Start timer final long startTime = System.currentTimeMillis(); for (int boxSize = maxBox; boxSize >= minBox; boxSize /= divBox) { if (verboseOutput) { IJ.showStatus("Estimating dimension, box size: " + boxSize); } bestCount = Long.MAX_VALUE; // init count for this boxSize final int increment = Math.max(1, boxSize / numOffsets); for (int gridOffsetX = 0; (gridOffsetX < boxSize) && (gridOffsetX < width); gridOffsetX += increment) { for (int gridOffsetY = 0; (gridOffsetY < boxSize) && (gridOffsetY < height); gridOffsetY += increment) { for (int gridOffsetZ = 0; (gridOffsetZ < boxSize) && (gridOffsetZ < depth); gridOffsetZ += increment) { count = 0; final int iMax = width + gridOffsetX; final int jMax = height + gridOffsetY; final int kMax = depth + gridOffsetZ; // Iterate over box-grid for (int i = 0; i <= iMax; i += boxSize) { xGrid = -gridOffsetX + i; for (int j = 0; j <= jMax; j += boxSize) { yGrid = -gridOffsetY + j; for (int k = 0; k <= kMax; k += boxSize) { zGrid = -gridOffsetZ + k; xStart = 0; if (xGrid < 0) { xStart = -xGrid; } if ((boxSize + xGrid) >= width) { xEnd = Math.min(width, (width - xGrid)); } else { xEnd = boxSize; } yStart = 0; if (yGrid < 0) { yStart = -yGrid; } if ((boxSize + yGrid) >= height) { yEnd = Math.min(height, (height - yGrid)); } else { yEnd = boxSize; } zStart = 0; if (zGrid < 0) { zStart = -zGrid; } if ((boxSize + zGrid) >= depth) { zEnd = Math.min(depth, (depth - zGrid)); } else { zEnd = boxSize; } for (int x = xStart; x < xEnd; x++) { xPos = x + xGrid; for (int y = yStart; y < yEnd; y++) { yPos = (y + yGrid); yPart = yPos * width; for (int z = zStart; z < zEnd; z++) { zPos = z + zGrid; // If pixel inside region, // count it if ((0xff & ((byte[]) surfaceImp.getStack().getPixels(zPos + 1)) [xPos + yPart]) >= threshold) { count++; z = x = y = boxSize; // stops // things } } } } } } } if (count < bestCount) { bestCount = count; } } } } xList.add(new Double(boxSize)); yList.add(new Double(bestCount)); } if (verboseOutput) { IJ.log("\nDuration: " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds\n"); } final double[] boxSizes = new double[xList.size()]; final double[] boxCountSums = new double[yList.size()]; for (int i = 0; i < boxSizes.length; i++) { boxSizes[i] = -Math.log((xList.get(i)).doubleValue()); boxCountSums[i] = Math.log((yList.get(i)).doubleValue()); } if (verboseOutput) { IJ.log( "Used " + boxSizes.length + " different box sizes, from " + maxBox + " to " + minBox); IJ.log( "with a reduction rate of " + divBox + " and " + numOffsets + " translations of each box."); } if (boxSizes.length == 0) { IJ.error( "\nError: No boxes!\n" + "Make sure that starting and ending box size and" + "reduction rate allow for at least one" + " box size to exist!"); return; } final CurveFitter cf = new CurveFitter(boxSizes, boxCountSums); cf.doFit(CurveFitter.STRAIGHT_LINE); final double[] p = cf.getParams(); final double RSq = cf.getRSquared(); if (verboseOutput) { IJ.log( imp.getTitle() + ": Dimension estimate: " + IJ.d2s(p[1], 4) + ": R²: " + RSq + ": Settings: " + maxBox + ":" + minBox + ":" + divBox + ":" + numOffsets); } if (verboseOutput) { IJ.log("Box Size Box Count"); for (int i = 0; i < boxSizes.length; i++) { IJ.log(IJ.d2s(xList.get(i), 0) + " " + IJ.d2s(yList.get(i), 0)); } } final ResultInserter ri = ResultInserter.getInstance(); ri.setResultInRow(imp, "Fractal Dimension", p[1]); ri.setResultInRow(imp, "R²", RSq); ri.updateTable(); if (plotGraph && !Interpreter.isBatchMode()) { drawGraph(p, boxSizes, boxCountSums); } } catch (final Exception e) { e.printStackTrace(); } UsageReporter.reportEvent(this).send(); }
public void run(String arg) { ImageCheck ic = new ImageCheck(); if (!ImageCheck.checkEnvironment()) return; ImagePlus imp = IJ.getImage(); if (!ic.isBinary(imp)) { IJ.error("8-bit binary (black and white only) image required."); return; } if (!ic.isVoxelIsotropic(imp, 1E-3)) { if (IJ.showMessageWithCancel( "Anisotropic voxels", "This image contains anisotropic voxels, which will\n" + "result in incorrect thickness calculation.\n\n" + "Consider rescaling your data so that voxels are isotropic\n" + "(Image > Scale...).\n\n" + "Continue anyway?")) { } else return; } GenericDialog gd = new GenericDialog("Options"); gd.addCheckbox("Thickness", true); gd.addCheckbox("Spacing", false); gd.addCheckbox("Graphic Result", true); gd.addCheckbox("Use_ROI_Manager", false); gd.addCheckbox("Mask thickness map", true); gd.addHelp("http://bonej.org/thickness"); gd.showDialog(); if (gd.wasCanceled()) { return; } boolean doThickness = gd.getNextBoolean(); boolean doSpacing = gd.getNextBoolean(); boolean doGraphic = gd.getNextBoolean(); boolean doRoi = gd.getNextBoolean(); boolean doMask = gd.getNextBoolean(); long startTime = System.currentTimeMillis(); String title = stripExtension(imp.getTitle()); RoiManager roiMan = RoiManager.getInstance(); // calculate trabecular thickness (Tb.Th) if (doThickness) { boolean inverse = false; ImagePlus impLTC = new ImagePlus(); if (doRoi && roiMan != null) { ImageStack stack = RoiMan.cropStack(roiMan, imp.getStack(), true, 0, 1); ImagePlus crop = new ImagePlus(imp.getTitle(), stack); crop.setCalibration(imp.getCalibration()); impLTC = getLocalThickness(crop, inverse, doMask); } else impLTC = getLocalThickness(imp, inverse, doMask); impLTC.setTitle(title + "_Tb.Th"); impLTC.setCalibration(imp.getCalibration()); double[] stats = StackStats.meanStdDev(impLTC); insertResults(imp, stats, inverse); if (doGraphic && !Interpreter.isBatchMode()) { impLTC.show(); impLTC.setSlice(1); impLTC.getProcessor().setMinAndMax(0, stats[2]); IJ.run("Fire"); } } if (doSpacing) { boolean inverse = true; ImagePlus impLTCi = new ImagePlus(); if (doRoi && roiMan != null) { ImageStack stack = RoiMan.cropStack(roiMan, imp.getStack(), true, 255, 1); ImagePlus crop = new ImagePlus(imp.getTitle(), stack); crop.setCalibration(imp.getCalibration()); impLTCi = getLocalThickness(crop, inverse, doMask); } else impLTCi = getLocalThickness(imp, inverse, doMask); // check marrow cavity size (i.e. trabcular separation, Tb.Sp) impLTCi.setTitle(title + "_Tb.Sp"); impLTCi.setCalibration(imp.getCalibration()); double[] stats = StackStats.meanStdDev(impLTCi); insertResults(imp, stats, inverse); if (doGraphic && !Interpreter.isBatchMode()) { impLTCi.show(); impLTCi.setSlice(1); impLTCi.getProcessor().setMinAndMax(0, stats[2]); IJ.run("Fire"); } } IJ.showProgress(1.0); IJ.showStatus("Done"); double duration = ((double) System.currentTimeMillis() - (double) startTime) / (double) 1000; IJ.log("Duration = " + IJ.d2s(duration, 3) + " s"); UsageReporter.reportEvent(this).send(); return; }
public void run(String arg) { int wOld, hOld, wNew, hNew; boolean fIsStack = false; ImagePlus imp = IJ.getImage(); wOld = imp.getWidth(); hOld = imp.getHeight(); ImageStack stackOld = imp.getStack(); if ((stackOld != null) && (stackOld.getSize() > 1)) fIsStack = true; String[] sPositions = { "Top-Left", "Top-Center", "Top-Right", "Center-Left", "Center", "Center-Right", "Bottom-Left", "Bottom-Center", "Bottom-Right" }; String strTitle = fIsStack ? "Resize Stack Canvas" : "Resize Image Canvas"; GenericDialog gd = new GenericDialog(strTitle); gd.addNumericField("Width:", wOld, 0, 5, "pixels"); gd.addNumericField("Height:", hOld, 0, 5, "pixels"); gd.addChoice("Position:", sPositions, sPositions[4]); gd.addCheckbox("Zero Fill", zeroFill); gd.showDialog(); if (gd.wasCanceled()) return; wNew = (int) gd.getNextNumber(); hNew = (int) gd.getNextNumber(); int iPos = gd.getNextChoiceIndex(); zeroFill = gd.getNextBoolean(); Prefs.set("resizer.zero", zeroFill); int xOff, yOff; int xC = (wNew - wOld) / 2; // offset for centered int xR = (wNew - wOld); // offset for right int yC = (hNew - hOld) / 2; // offset for centered int yB = (hNew - hOld); // offset for bottom switch (iPos) { case 0: // TL xOff = 0; yOff = 0; break; case 1: // TC xOff = xC; yOff = 0; break; case 2: // TR xOff = xR; yOff = 0; break; case 3: // CL xOff = 0; yOff = yC; break; case 4: // C xOff = xC; yOff = yC; break; case 5: // CR xOff = xR; yOff = yC; break; case 6: // BL xOff = 0; yOff = yB; break; case 7: // BC xOff = xC; yOff = yB; break; case 8: // BR xOff = xR; yOff = yB; break; default: // center xOff = xC; yOff = yC; break; } if (fIsStack) { ImageStack stackNew = expandStack(stackOld, wNew, hNew, xOff, yOff); imp.setStack(null, stackNew); } else { if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER, imp); ImageWindow win = imp.getWindow(); if (win != null && (win instanceof PlotWindow)) ((PlotWindow) win).getPlot().setFrozen(true); ImageProcessor newIP = expandImage(imp.getProcessor(), wNew, hNew, xOff, yOff); imp.setProcessor(null, newIP); if (!IJ.macroRunning()) Undo.setup(Undo.COMPOUND_FILTER_DONE, imp); } Overlay overlay = imp.getOverlay(); if (overlay != null) overlay.translate(xOff, yOff); }
@Override public void run(String arg) { final ImagePlus imp = IJ.getImage(); run(IJ.getImage().getProcessor(), 0); imp.updateAndDraw(); }
/** Ask for parameters and then execute. */ public void run(String arg) { // 1 - Obtain the currently active image: ImagePlus imp = IJ.getImage(); if (null == imp) { IJ.showMessage("There must be at least one image open"); return; } if (imp.getBitDepth() != 8) { IJ.showMessage("Error", "Only 8-bit images are supported"); return; } // 2 - Ask for parameters: GenericDialog gd = new GenericDialog("Auto Local Threshold"); String[] methods = { "Try all", "Bernsen", "Contrast", "Mean", "Median", "MidGrey", "Niblack", "Otsu", "Phansalkar", "Sauvola" }; gd.addMessage("Auto Local Threshold v1.5"); gd.addChoice("Method", methods, methods[0]); gd.addNumericField("Radius", 15, 0); gd.addMessage("Special paramters (if different from default)"); gd.addNumericField("Parameter_1", 0, 0); gd.addNumericField("Parameter_2", 0, 0); gd.addCheckbox("White objects on black background", true); if (imp.getStackSize() > 1) { gd.addCheckbox("Stack", false); } gd.addMessage("Thresholded result is always shown in white [255]."); gd.showDialog(); if (gd.wasCanceled()) return; // 3 - Retrieve parameters from the dialog String myMethod = gd.getNextChoice(); int radius = (int) gd.getNextNumber(); double par1 = (double) gd.getNextNumber(); double par2 = (double) gd.getNextNumber(); boolean doIwhite = gd.getNextBoolean(); boolean doIstack = false; int stackSize = imp.getStackSize(); if (stackSize > 1) doIstack = gd.getNextBoolean(); // 4 - Execute! // long start = System.currentTimeMillis(); if (myMethod.equals("Try all")) { ImageProcessor ip = imp.getProcessor(); int xe = ip.getWidth(); int ye = ip.getHeight(); int ml = methods.length; ImagePlus imp2, imp3; ImageStack tstack = null, stackNew; if (stackSize > 1 && doIstack) { boolean doItAnyway = true; if (stackSize > 25) { YesNoCancelDialog d = new YesNoCancelDialog( IJ.getInstance(), "Auto Local Threshold", "You might run out of memory.\n \nDisplay " + stackSize + " slices?\n \n \'No\' will process without display and\noutput results to the log window."); if (!d.yesPressed()) { // doIlog=true; //will show in the log window doItAnyway = false; } if (d.cancelPressed()) return; } for (int j = 1; j <= stackSize; j++) { imp.setSlice(j); ip = imp.getProcessor(); tstack = new ImageStack(xe, ye); for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate()); imp2 = new ImagePlus("Auto Threshold", tstack); imp2.updateAndDraw(); for (int k = 1; k < ml; k++) { imp2.setSlice(k); Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite); } // if (doItAnyway){ CanvasResizer cr = new CanvasResizer(); stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1); imp3 = new ImagePlus("Auto Threshold", stackNew); imp3.updateAndDraw(); MontageMaker mm = new MontageMaker(); mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true); // 3 columns and 3 rows } imp.setSlice(1); // if (doItAnyway) IJ.run("Images to Stack", "method=[Copy (center)] title=Montage"); return; } else { // single image try all tstack = new ImageStack(xe, ye); for (int k = 1; k < ml; k++) tstack.addSlice(methods[k], ip.duplicate()); imp2 = new ImagePlus("Auto Threshold", tstack); imp2.updateAndDraw(); for (int k = 1; k < ml; k++) { imp2.setSlice(k); // IJ.log("analyzing slice with "+methods[k]); Object[] result = exec(imp2, methods[k], radius, par1, par2, doIwhite); } // imp2.setSlice(1); CanvasResizer cr = new CanvasResizer(); stackNew = cr.expandStack(tstack, (xe + 2), (ye + 18), 1, 1); imp3 = new ImagePlus("Auto Threshold", stackNew); imp3.updateAndDraw(); MontageMaker mm = new MontageMaker(); mm.makeMontage(imp3, 3, 3, 1.0, 1, (ml - 1), 1, 0, true); return; } } else { // selected a method if (stackSize > 1 && doIstack) { // whole stack // if (doIstackHistogram) {// one global histogram // Object[] result = exec(imp, myMethod, noWhite, noBlack, doIwhite, doIset, doIlog, // doIstackHistogram ); // } // else{ // slice by slice for (int k = 1; k <= stackSize; k++) { imp.setSlice(k); Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite); } // } imp.setSlice(1); } else { // just one slice Object[] result = exec(imp, myMethod, radius, par1, par2, doIwhite); } // 5 - If all went well, show the image: // not needed here as the source image is binarised } }
void addImage() { ImagePlus imp = IJ.getImage(); int[] wList = WindowManager.getIDList(); if (wList == null || wList.length < 2) { IJ.error("Add Image...", "The command requires at least two open images."); return; } String[] titles = new String[wList.length]; for (int i = 0; i < wList.length; i++) { ImagePlus imp2 = WindowManager.getImage(wList[i]); titles[i] = imp2 != null ? imp2.getTitle() : ""; } int x = 0, y = 0; Roi roi = imp.getRoi(); if (roi != null && roi.isArea()) { Rectangle r = roi.getBounds(); x = r.x; y = r.y; } int index = 0; if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) index = 1; } else if (imp.getID() == wList[0]) index = 1; GenericDialog gd = new GenericDialog("Add Image..."); gd.addChoice("Image to add:", titles, titles[index]); gd.addNumericField("X location:", x, 0); gd.addNumericField("Y location:", y, 0); gd.addNumericField("Opacity (0-100%):", 100, 0); gd.addCheckbox("Create image selection", createImageRoi); gd.showDialog(); if (gd.wasCanceled()) return; index = gd.getNextChoiceIndex(); x = (int) gd.getNextNumber(); y = (int) gd.getNextNumber(); double opacity = gd.getNextNumber() / 100.0; createImageRoi = gd.getNextBoolean(); ImagePlus overlay = WindowManager.getImage(wList[index]); if (wList.length == 2) { ImagePlus i1 = WindowManager.getImage(wList[0]); ImagePlus i2 = WindowManager.getImage(wList[1]); if (i2.getWidth() < i1.getWidth() && i2.getHeight() < i1.getHeight()) { imp = i1; overlay = i2; } } if (overlay == imp) { IJ.error( "Add Image...", "Image to be added cannot be the same as\n\"" + imp.getTitle() + "\"."); return; } if (overlay.getWidth() > imp.getWidth() && overlay.getHeight() > imp.getHeight()) { IJ.error( "Add Image...", "Image to be added cannnot be larger than\n\"" + imp.getTitle() + "\"."); return; } if (createImageRoi && x == 0 && y == 0) { x = imp.getWidth() / 2 - overlay.getWidth() / 2; y = imp.getHeight() / 2 - overlay.getHeight() / 2; } roi = new ImageRoi(x, y, overlay.getProcessor()); roi.setName(overlay.getShortTitle()); if (opacity != 1.0) ((ImageRoi) roi).setOpacity(opacity); if (createImageRoi) imp.setRoi(roi); else { Overlay overlayList = imp.getOverlay(); if (overlayList == null) overlayList = new Overlay(); overlayList.add(roi); imp.setOverlay(overlayList); overlay2 = overlayList; Undo.setup(Undo.OVERLAY_ADDITION, imp); } }
public void run(String arg) { imp = IJ.getImage(); showDialog(); }
public void run(String arg) { imp = IJ.getImage(); int stackSize = imp.getStackSize(); if (imp == null) { IJ.noImage(); return; } // Make sure input image is a stack. if (stackSize == 1) { IJ.error("Z Project", "Stack required"); return; } // Check for inverting LUT. if (imp.getProcessor().isInvertedLut()) { if (!IJ.showMessageWithCancel("ZProjection", lutMessage)) return; } // Set default bounds. int channels = imp.getNChannels(); int frames = imp.getNFrames(); int slices = imp.getNSlices(); isHyperstack = imp.isHyperStack() || (ij.macro.Interpreter.isBatchMode() && ((frames > 1 && frames < stackSize) || (slices > 1 && slices < stackSize))); boolean simpleComposite = channels == stackSize; if (simpleComposite) isHyperstack = false; startSlice = 1; if (isHyperstack) { int nSlices = imp.getNSlices(); if (nSlices > 1) stopSlice = nSlices; else stopSlice = imp.getNFrames(); } else stopSlice = stackSize; // Build control dialog GenericDialog gd = buildControlDialog(startSlice, stopSlice); gd.showDialog(); if (gd.wasCanceled()) return; if (!imp.lock()) return; // exit if in use long tstart = System.currentTimeMillis(); setStartSlice((int) gd.getNextNumber()); setStopSlice((int) gd.getNextNumber()); method = gd.getNextChoiceIndex(); Prefs.set(METHOD_KEY, method); if (isHyperstack) { allTimeFrames = imp.getNFrames() > 1 && imp.getNSlices() > 1 ? gd.getNextBoolean() : false; doHyperStackProjection(allTimeFrames); } else if (imp.getType() == ImagePlus.COLOR_RGB) doRGBProjection(true); else doProjection(true); if (arg.equals("") && projImage != null) { long tstop = System.currentTimeMillis(); projImage.setCalibration(imp.getCalibration()); if (simpleComposite) IJ.run(projImage, "Grays", ""); projImage.show("ZProjector: " + IJ.d2s((tstop - tstart) / 1000.0, 2) + " seconds"); } imp.unlock(); IJ.register(ZProjector.class); return; }