/** Converts a y-coordinate in pixels to physical units (e.g. mm), taking into account the invertY and global "Invert Y Coordinates" flags. */ public double getY(double y, int imageHeight) { if (invertY || (Analyzer.getMeasurements()&Measurements.INVERT_Y)!=0) { if (yOrigin!=0.0) return (yOrigin-y)*pixelHeight; else return (imageHeight-y-1)*pixelHeight; } else return (y-yOrigin)*pixelHeight; }
/** Converts a y-coodinate in physical units to pixels, taking into account the 'invertY' flag. */ public double getRawY(double y, int imageHeight) { if (invertY || (Analyzer.getMeasurements()&Measurements.INVERT_Y)!=0) { if (yOrigin!=0.0) return yOrigin-y/pixelHeight; else return imageHeight -y/pixelHeight - 1; } else return y/pixelHeight + yOrigin; }
/** Converts a y-coordinate in pixels to physical units (e.g. mm), taking into account the invertY and global "Invert Y Coordinates" flags. */ public double getY(double y, int imageHeight) { if (invertY || (Analyzer.getMeasurements()&Measurements.INVERT_Y)!=0) { if (yOrigin!=0.0) return (yOrigin-y)*pixelHeight; else return (imageHeight-y-1)*pixelHeight; } else return (y-yOrigin)*pixelHeight; }
/** Converts a y-coodinate in physical units to pixels, taking into account the 'invertY' flag. */ public double getRawY(double y, int imageHeight) { if (invertY || (Analyzer.getMeasurements()&Measurements.INVERT_Y)!=0) { if (yOrigin!=0.0) return yOrigin-y/pixelHeight; else return imageHeight -y/pixelHeight - 1; } else return y/pixelHeight + yOrigin; }
/** Construct a new Analyzer using an ImagePlus object and a ResultsTable. */ public Analyzer(ImagePlus imp, ResultsTable rt) { this(imp, Analyzer.getMeasurements(), rt); }
public static boolean addToOverlay() { return ((getMeasurements()&ADD_TO_OVERLAY)!=0); }
public static boolean addToOverlay() { return ((getMeasurements()&ADD_TO_OVERLAY)!=0); }
/** Construct a new Analyzer using an ImagePlus object and a ResultsTable. */ public Analyzer(ImagePlus imp, ResultsTable rt) { this(imp, Analyzer.getMeasurements(), rt); }
/** * Retrieves precision according to {@code Analyze>Set Measurements...} * * @return the number of decimal digits to be used in tables */ protected int getScientificNotationAwarePrecision() { final boolean sNotation = (Analyzer.getMeasurements() & Measurements.SCIENTIFIC_NOTATION) != 0; int precision = Analyzer.getPrecision(); if (sNotation) precision = -precision; return precision; }
/** Save the image as tab-delimited text using the specified path. */ public boolean saveAsText(String path) { DataOutputStream out = null; try { Calibration cal = imp.getCalibration(); int precision = Analyzer.getPrecision(); int measurements = Analyzer.getMeasurements(); boolean scientificNotation = (measurements&Measurements.SCIENTIFIC_NOTATION)!=0; if (scientificNotation) precision = -precision; TextEncoder file = new TextEncoder(imp.getProcessor(), cal, precision); out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path))); file.write(out); out.close(); } catch (IOException e) { showErrorMessage("saveAsText", path, e); return false; } finally { if (out!=null) try {out.close();} catch (IOException e) {} } return true; }
/** get the number of digits for writing a column to the results table or the clipboard */ static int getPrecision(float[] values) { int setDigits = Analyzer.getPrecision(); int measurements = Analyzer.getMeasurements(); boolean scientificNotation = (measurements&Measurements.SCIENTIFIC_NOTATION)!=0; if (scientificNotation) { if (setDigits<MIN_SCIENTIFIC_DIGITS) setDigits = MIN_SCIENTIFIC_DIGITS; return -setDigits; } boolean allInteger = true; float min = Float.MAX_VALUE, max = -Float.MAX_VALUE; for (int i=0; i<values.length; i++) { if ((int)values[i]!=values[i] && !Float.isNaN(values[i])) { allInteger = false; if (values[i] < min) min = values[i]; if (values[i] > max) max = values[i]; } } if (allInteger) return 0; int digits = (max - min) > 0 ? getDigits(min, max, MIN_FLOAT_PRECISION*(max-min), 15) : getDigits(max, MIN_FLOAT_PRECISION*Math.abs(max), 15); if (setDigits>Math.abs(digits)) digits = setDigits * (digits < 0 ? -1 : 1); //use scientific notation if needed return digits; }
/** Save the image as tab-delimited text using the specified path. */ public boolean saveAsText(String path) { DataOutputStream out = null; try { Calibration cal = imp.getCalibration(); int precision = Analyzer.getPrecision(); int measurements = Analyzer.getMeasurements(); boolean scientificNotation = (measurements&Measurements.SCIENTIFIC_NOTATION)!=0; if (scientificNotation) precision = -precision; TextEncoder file = new TextEncoder(imp.getProcessor(), cal, precision); out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path))); file.write(out); out.close(); } catch (IOException e) { showErrorMessage("saveAsText", path, e); return false; } finally { if (out!=null) try {out.close();} catch (IOException e) {} } return true; }
/** * 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); }
private static void setStackThreshold(ImagePlus imp, ImageProcessor ip, String method) { boolean darkBackground = method.indexOf("dark")!=-1; int measurements = Analyzer.getMeasurements(); Analyzer.setMeasurements(Measurements.AREA+Measurements.MIN_MAX); ImageStatistics stats = new StackStatistics(imp);
allSliceOne=false; int measurements = Analyzer.getMeasurements(); if (imp.getStackSize()>1) Analyzer.setMeasurements(measurements|Measurements.SLICE);
/** 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); }
/** 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); }
void sum8BitHistograms(ImagePlus imp) { Calibration cal = imp.getCalibration(); boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; int minThreshold = 0; int maxThreshold = 255; ImageProcessor ip = imp.getProcessor(); if (limitToThreshold && ip.getMinThreshold()!=ImageProcessor.NO_THRESHOLD) { minThreshold = (int)ip.getMinThreshold(); maxThreshold = (int)ip.getMaxThreshold(); } ImageStack stack = imp.getStack(); Roi roi = imp.getRoi(); longHistogram = new long[256]; int n = stack.getSize(); for (int slice=1; slice<=n; slice++) { IJ.showProgress(slice, n); ip = stack.getProcessor(slice); if (roi!=null) ip.setRoi(roi); int[] hist = ip.getHistogram(); for (int i=0; i<256; i++) longHistogram[i] += hist[i]; } pw=1.0; ph=1.0; getRawStatistics(longHistogram, minThreshold, maxThreshold); getRawMinAndMax(longHistogram, minThreshold, maxThreshold); copyHistogram(256); IJ.showStatus(""); IJ.showProgress(1.0); }
void sum16BitHistograms(ImagePlus imp) { Calibration cal = imp.getCalibration(); boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; int minThreshold = 0; int maxThreshold = 65535;
this.stats = stats; cal = imp.getCalibration(); boolean limitToThreshold = (Analyzer.getMeasurements()&LIMIT)!=0; imp.getMask(); histogram = stats.getHistogram();