MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getHistogram

Method getHistogram

ij/src/main/java/ij/macro/Functions.java:2043–2110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2041 }
2042
2043 void getHistogram() {
2044 interp.getLeftParen();
2045 Variable values = null;
2046 if (interp.nextToken()==NUMBER)
2047 interp.getExpression();
2048 else
2049 values = getArrayVariable();
2050 Variable counts = getNextArrayVariable();
2051 interp.getComma();
2052 int nBins = (int)interp.getExpression();
2053 ImagePlus imp = getImage();
2054 double histMin=0.0, histMax=0.0;
2055 boolean setMinMax = false;
2056 int bitDepth = imp.getBitDepth();
2057 if (interp.nextToken()==',') {
2058 histMin = getNextArg();
2059 histMax = getLastArg();
2060 if (bitDepth==8 || bitDepth==24)
2061 interp.error("16 or 32-bit image required to set histMin and histMax");
2062 setMinMax = true;
2063 } else
2064 interp.getRightParen();
2065 if (nBins==65536 && bitDepth==16) {
2066 Variable[] array = counts.getArray();
2067 ImageProcessor ip = imp.getProcessor();
2068 Roi roi = imp.getRoi();
2069 if (roi!=null)
2070 ip.setRoi(roi);
2071 int[] hist = ip.getHistogram();
2072 if (array!=null && array.length==nBins) {
2073 for (int i=0; i<nBins; i++)
2074 array[i].setValue(hist[i]);
2075 } else
2076 counts.setArray(new Variable(hist).getArray());
2077 return;
2078 }
2079 ImageStatistics stats;
2080 boolean custom8Bit = false;
2081 if ((bitDepth==8||bitDepth==24) && nBins!=256) {
2082 ImageProcessor ip = imp.getProcessor().convertToShort(false);
2083 imp = imp.createImagePlus();
2084 imp.setProcessor(ip);
2085 stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX, nBins, 0, 256);
2086 custom8Bit = true;
2087 } else if (setMinMax)
2088 stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX, nBins, histMin, histMax);
2089 else
2090 stats = imp.getStatistics(AREA+MEAN+MODE+MIN_MAX, nBins);
2091 if (values!=null) {
2092 Calibration cal = imp.getCalibration();
2093 double[] array = new double[nBins];
2094 double value = cal.getCValue(stats.histMin);
2095 double inc = 1.0;
2096 if (bitDepth==16 || bitDepth==32 || cal.calibrated() || custom8Bit)
2097 inc = (cal.getCValue(stats.histMax) - cal.getCValue(stats.histMin))/stats.nBins;
2098 for (int i=0; i<nBins; i++) {
2099 array[i] = value;
2100 value += inc;

Callers 1

doFunctionMethod · 0.95

Calls 15

getArrayVariableMethod · 0.95
getNextArrayVariableMethod · 0.95
getImageMethod · 0.95
getBitDepthMethod · 0.95
getNextArgMethod · 0.95
getLastArgMethod · 0.95
getArrayMethod · 0.95
getProcessorMethod · 0.95
getRoiMethod · 0.95
setRoiMethod · 0.95
getHistogramMethod · 0.95
setArrayMethod · 0.95

Tested by

no test coverage detected