longHistogram[index] += count; copyHistogram(nBins); pixelCount = (int)longPixelCount; area = longPixelCount*pw*ph; mean = sum/longPixelCount; umean = mean; dmode = getMode(null); calculateStdDev(longPixelCount, sum, sum2);
/** Creates a StackStatistics object from a stack, using the specified histogram bin count and x-axis range (pixel value tange). */ public StackStatistics(ImagePlus imp, int nBins, double xMin, double xMax) { int bits = imp.getBitDepth(); stackStatistics = true; if ((bits==8||bits==24) && nBins==256 && xMin==0.0 && xMax==256.0) sum8BitHistograms(imp); else if (bits==16 && nBins==256 && xMin==0.0 && xMax==0.0 && !imp.getCalibration().calibrated()) sum16BitHistograms(imp); else doCalculations(imp, nBins, xMin, xMax); }
/** * Multiplies all pixel values in the result image by pixelWidth. This ways * the pixel values represent sample thickness in real units. * * @throws NullPointerException If this.resultImage == null */ private void pixelValuesToCalibratedValues() { if (resultImage == null) { throw new NullPointerException( "The resultImage in LocalThicknessWrapper is null"); } final double pixelWidth = resultImage.getCalibration().pixelWidth; final ImageStack stack = resultImage.getStack(); final int depth = stack.getSize(); for (int z = 1; z <= depth; z++) { stack.getProcessor(z).multiply(pixelWidth); } final StackStatistics stackStatistics = new StackStatistics(resultImage); final double maxPixelValue = stackStatistics.max; resultImage.getProcessor().setMinAndMax(0, maxPixelValue); }
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); }
getRaw16BitMinAndMax(hist16, minThreshold, maxThreshold); get16BitStatistics(hist16, (int)min, (int)max); histogram16 = new int[65536]; for (int i=0; i<65536; i++) {
void getRawStatistics(long[] histogram, int minThreshold, int maxThreshold) { long count; long longMaxCount = 0L; double value; double sum = 0.0; double sum2 = 0.0; for (int i=minThreshold; i<=maxThreshold; i++) { count = histogram[i]; longPixelCount += count; sum += (double)i*count; value = i; sum2 += (value*value)*count; if (count>longMaxCount) { longMaxCount = count; mode = i; } } maxCount = (int)longMaxCount; pixelCount = (int)longPixelCount; area = longPixelCount*pw*ph; mean = sum/longPixelCount; umean = mean; dmode = mode; calculateStdDev(longPixelCount, sum, sum2); histMin = 0.0; histMax = 255.0; }
stats = new StackStatistics(new PatchStack(sub.toArray(new Patch[sub.size()]), 1)); } else { stats = reference_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); }
getRaw16BitMinAndMax(hist16, minThreshold, maxThreshold); get16BitStatistics(hist16, (int)min, (int)max); histogram16 = new int[65536]; for (int i=0; i<65536; i++) {
void getRawStatistics(long[] histogram, int minThreshold, int maxThreshold) { long count; long longMaxCount = 0L; double value; double sum = 0.0; double sum2 = 0.0; for (int i=minThreshold; i<=maxThreshold; i++) { count = histogram[i]; longPixelCount += count; sum += (double)i*count; value = i; sum2 += (value*value)*count; if (count>longMaxCount) { longMaxCount = count; mode = i; } } maxCount = (int)longMaxCount; pixelCount = (int)longPixelCount; area = longPixelCount*pw*ph; mean = sum/longPixelCount; umean = mean; dmode = mode; calculateStdDev(longPixelCount, sum, sum2); histMin = 0.0; histMax = 255.0; }
ImageStatistics stats = new StackStatistics(imp, nBins, nMin, nMax); int maxCount = 0; for (int i=0; i<stats.histogram.length; i++) {
longHistogram[index] += count; copyHistogram(nBins); pixelCount = (int)longPixelCount; area = longPixelCount*pw*ph; mean = sum/longPixelCount; umean = mean; dmode = getMode(null); calculateStdDev(longPixelCount, sum, sum2);
/** Creates a StackStatistics object from a stack, using the specified histogram bin count and x-axis range (pixel value tange). */ public StackStatistics(ImagePlus imp, int nBins, double xMin, double xMax) { int bits = imp.getBitDepth(); stackStatistics = true; if ((bits==8||bits==24) && nBins==256 && xMin==0.0 && xMax==256.0) sum8BitHistograms(imp); else if (bits==16 && nBins==256 && xMin==0.0 && xMax==0.0 && !imp.getCalibration().calibrated()) sum16BitHistograms(imp); else doCalculations(imp, nBins, xMin, xMax); }
ImageStatistics stats = new StackStatistics(imp, nBins, nMin, nMax); int maxCount = 0; for (int i=0; i<stats.histogram.length; i++) {
area = longPixelCount*pw*ph; mean = sum/longPixelCount; calculateStdDev(longPixelCount, sum, sum2); histMin = cal.getRawValue(histMin); histMax = cal.getRawValue(histMax); if (histMin==0.0 && histMax==256.0 && (bits==8||bits==24)) histMax = 255.0; dmode = getMode(cal); copyHistogram(nBins); IJ.showStatus(""); IJ.showProgress(1.0);
int measurements = Analyzer.getMeasurements(); Analyzer.setMeasurements(Measurements.AREA+Measurements.MIN_MAX); ImageStatistics stats = new StackStatistics(imp); Analyzer.setMeasurements(measurements); AutoThresholder thresholder = new AutoThresholder();
area = longPixelCount*pw*ph; mean = sum/longPixelCount; calculateStdDev(longPixelCount, sum, sum2); histMin = cal.getRawValue(histMin); histMax = cal.getRawValue(histMax); if (histMin==0.0 && histMax==256.0 && (bits==8||bits==24)) histMax = 255.0; dmode = getMode(cal); copyHistogram(nBins); IJ.showStatus(""); IJ.showProgress(1.0);
int measurements = Analyzer.getMeasurements(); Analyzer.setMeasurements(Measurements.AREA+Measurements.MIN_MAX); ImageStatistics stats = new StackStatistics(imp); Analyzer.setMeasurements(measurements); AutoThresholder thresholder = new AutoThresholder();
void invert16BitStack(ImagePlus imp) { imp.deleteRoi(); imp.getCalibration().disableDensityCalibration(); ImageStatistics stats = new StackStatistics(imp); ImageStack stack = imp.getStack(); int nslices = stack.getSize(); int min=(int)stats.min, range=(int)(stats.max-stats.min); int n = imp.getWidth()*imp.getHeight(); for (int slice=1; slice<=nslices; slice++) { ImageProcessor ip = stack.getProcessor(slice); short[] pixels = (short[])ip.getPixels(); for (int i=0; i<n; i++) { int before = pixels[i]&0xffff; pixels[i] = (short)(range-((pixels[i]&0xffff)-min)); } } imp.setStack(null, stack); imp.setDisplayRange(0, range); imp.updateAndDraw(); }
ImageStatistics stats = new StackStatistics(imp, nBins, nMin, nMax); int maxCount = 0; for(int i = 0; i < stats.histogram.length; i++) {