()
| 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; |
no test coverage detected