2 import ij.measure.Calibration;
11 this(ip, AREA+MEAN+MODE+MIN_MAX, null);
22 double minThreshold,maxThreshold;
24 {minThreshold=-Float.MAX_VALUE; maxThreshold=Float.MAX_VALUE;}
27 getStatistics(ip, minThreshold, maxThreshold);
28 if ((mOptions&MODE)!=0)
30 if ((mOptions&ELLIPSE)!=0)
32 else if ((mOptions&CENTROID)!=0)
33 getCentroid(ip, minThreshold, maxThreshold);
34 if ((mOptions&CENTER_OF_MASS)!=0)
35 getCenterOfMass(ip, minThreshold, maxThreshold);
38 void getStatistics(
ImageProcessor ip,
double minThreshold,
double maxThreshold) {
44 histogram =
new int[nBins];
50 double roiMin = Double.MAX_VALUE;
51 double roiMax = -Double.MAX_VALUE;
52 double roiMin2 = Double.MAX_VALUE;
53 double roiMax2 = -Double.MAX_VALUE;
54 for (
int y=ry, my=0; y<(ry+rh); y++, my++) {
55 int i = y * width + rx;
57 for (
int x=rx; x<(rx+rw); x++) {
58 if (mask==null || mask[mi++]!=0) {
60 if (v>=minThreshold && v<=maxThreshold) {
61 if (v<roiMin) roiMin = v;
62 if (v>roiMax) roiMax = v;
68 min = roiMin; max = roiMax;
69 if (histMin==0.0 && histMax==0.0) {
73 if (min<histMin) min = histMin;
74 if (max>histMax) max = histMax;
76 binSize = (histMax-histMin)/nBins;
79 double scale = nBins/(histMax-histMin);
82 for (
int y=ry, my=0; y<(ry+rh); y++, my++) {
83 int i = y * width + rx;
85 for (
int x=rx; x<(rx+rw); x++) {
86 if (mask==null || mask[mi++]!=0) {
88 if (v>=minThreshold && v<=maxThreshold && v>=histMin && v<=histMax) {
92 index = (int)(scale*(v-histMin));
101 area = pixelCount*pw*ph;
102 mean = sum/pixelCount;
103 calculateStdDev(pixelCount, sum, sum2);
109 for (
int i = 0; i < nBins; i++) {
110 count = histogram[i];
111 if (count > maxCount) {
116 dmode = histMin+mode*binSize;
118 dmode += binSize/2.0;
121 void getCenterOfMass(ImageProcessor ip,
double minThreshold,
double maxThreshold) {
122 float[] pixels = (
float[])ip.getPixels();
123 byte[] mask = ip.getMaskArray();
125 double v, count=0.0, xsum=0.0, ysum=0.0;
126 for (
int y=ry,my=0; y<(ry+rh); y++,my++) {
129 for (
int x=rx; x<(rx+rw); x++) {
130 if (mask==null || mask[mi++]!=0) {
131 v = pixels[i]+Double.MIN_VALUE;
132 if (v>=minThreshold && v<=maxThreshold) {
141 xCenterOfMass = (xsum/count+0.5)*pw;
142 yCenterOfMass = (ysum/count+0.5)*ph;
145 void getCentroid(ImageProcessor ip,
double minThreshold,
double maxThreshold) {
146 float[] pixels = (
float[])ip.getPixels();
147 byte[] mask = ip.getMaskArray();
148 double count=0.0, xsum=0.0, ysum=0.0, v;
150 for (
int y=ry,my=0; y<(ry+rh); y++,my++) {
153 for (
int x=rx; x<(rx+rw); x++) {
154 if (mask==null||mask[mi++]!=0) {
156 if (v>=minThreshold && v<=maxThreshold) {
165 xCentroid = ((double)xsum/count+0.5)*pw;
166 yCentroid = ((double)ysum/count+0.5)*ph;