2 import ij.measure.Calibration;
11 this(ip, AREA+MEAN+MODE+MIN_MAX, null);
23 int minThreshold,maxThreshold;
25 {minThreshold=0; maxThreshold=65535;}
29 float[] cTable = cal!=null?cal.
getCTable():null;
30 getRawMinAndMax(hist, minThreshold, maxThreshold);
33 getStatistics(hist, (
int)min, (
int)max, cTable);
34 if ((mOptions&MODE)!=0)
36 if ((mOptions&ELLIPSE)!=0)
38 else if ((mOptions&CENTROID)!=0)
39 getCentroid(ip, minThreshold, maxThreshold);
40 if ((mOptions&CENTER_OF_MASS)!=0)
41 getCenterOfMass(ip, minThreshold, maxThreshold);
42 if ((mOptions&MIN_MAX)!=0 && cTable!=null) {
43 getCalibratedMinAndMax(hist, (
int)min, (
int)max, cTable);
47 void getRawMinAndMax(
int[] hist,
int minThreshold,
int maxThreshold) {
48 int min = minThreshold;
49 while ((hist[min]==0) && (min<65535))
53 int max = maxThreshold;
54 while ((hist[max]==0) && (max>0))
59 void getStatistics(
int[] hist,
int min,
int max,
float[] cTable) {
64 binSize = (histMax-histMin)/nBins;
65 double scale = 1.0/binSize;
66 int hMin = (int)histMin;
67 histogram =
new int[nBins];
71 for (
int i=min; i<=max; i++) {
78 value = cTable==null?i:cTable[i];
80 sum2 += (value*value)*count;
81 index = (int)(scale*(i-hMin));
84 histogram[index] += count;
86 area = pixelCount*pw*ph;
87 mean = sum/pixelCount;
89 calculateStdDev(pixelCount, sum, sum2);
91 dmode = cTable[(int)dmode];
97 for (
int i=0; i<nBins; i++) {
99 if (count > maxCount) {
108 void getCentroid(ImageProcessor ip,
int minThreshold,
int maxThreshold) {
109 short[] pixels = (
short[])ip.getPixels();
110 byte[] mask = ip.getMaskArray();
111 boolean limit = minThreshold>0 || maxThreshold<65535;
112 int count=0, xsum=0, ysum=0,i,mi,v;
113 for (
int y=ry,my=0; y<(ry+rh); y++,my++) {
116 for (
int x=rx; x<(rx+rw); x++) {
117 if (mask==null||mask[mi++]!=0) {
119 v = pixels[i]&0xffff;
120 if (v>=minThreshold&&v<=maxThreshold) {
134 xCentroid = ((double)xsum/count+0.5)*pw;
135 yCentroid = ((double)ysum/count+0.5)*ph;
138 void getCenterOfMass(ImageProcessor ip,
int minThreshold,
int maxThreshold) {
139 short[] pixels = (
short[])ip.getPixels();
140 byte[] mask = ip.getMaskArray();
142 double dv, count=0.0, xsum=0.0, ysum=0.0;
143 for (
int y=ry,my=0; y<(ry+rh); y++,my++) {
146 for (
int x=rx; x<(rx+rw); x++) {
147 if (mask==null || mask[mi++]!=0) {
148 v = pixels[i]&0xffff;
149 if (v>=minThreshold&&v<=maxThreshold) {
158 xCenterOfMass = (xsum/count+0.5)*pw;
159 yCenterOfMass = (ysum/count+0.5)*ph;
162 void getCalibratedMinAndMax(
int[] hist,
int minValue,
int maxValue,
float[] cTable) {
163 min = Double.MAX_VALUE;
164 max = -Double.MAX_VALUE;
166 for (
int i=minValue; i<=maxValue; i++) {