Searching min and max in IMG data.
More...
Go to the source code of this file.
|
int | imgMax (IMG *img, float *maxvalue) |
|
int | imgAbsMax (IMG *img, float *maxvalue) |
|
int | imgRangeMinMax (IMG *img, IMG_RANGE *r, IMG_PIXEL *maxp, float *maxv, IMG_PIXEL *minp, float *minv) |
|
int | imgMinMax (IMG *img, float *minvalue, float *maxvalue) |
|
int | imgFrameMinMax (IMG *img, int frame, float *minvalue, float *maxvalue) |
|
int | imgReadMinMax (const char *fname, float *fmin, float *fmax) |
|
int | imgSmoothMax (IMG *img, float *maxvalue, IMG_PIXEL *p) |
|
int | imgGetPeak (IMG *img, float beforeTime, IMG_PIXEL *p, int verbose) |
|
int | imgGetMaxTime (IMG *img, IMG *mimg, const int w, int verbose) |
|
int | imgGetMaxFrame (IMG *img, IMG *mimg, int verbose) |
|
int | imgAvg (IMG *img, IMG_RANGE *r, float *avg) |
|
float | f_kth_smallest (float *data, long long int n, long long int k) |
|
float | fmedian (float *data, long long int n) |
|
float | fmean (float *data, long long int n, float *sd) |
|
void | fMinMaxFin (float *data, long long int n, float *fmin, float *fmax) |
|
Searching min and max in IMG data.
- Author
- Vesa Oikonen
Definition in file imgminmax.c.
◆ f_kth_smallest()
float f_kth_smallest |
( |
float * | data, |
|
|
long long int | n, |
|
|
long long int | k ) |
Returns the kth smallest value in data[0..n-1].
Array is partially sorted. Algorithm is based on the book Wirth N. Algorithms + data structures = programs. Englewood Cliffs, Prentice-Hall, 1976.
- See also
- fmedian
- Returns
- Returns the kth smallest value in data[0..n-1].
- Parameters
-
data | Pointer to data; array is partially sorted |
n | Length of data array |
k | kth smallest value will be returned |
Definition at line 558 of file imgminmax.c.
565 {
566 long long int i, j, l, m;
567 float x, s;
568
569 l=0; m=n-1;
570 while(l<m) {
571 x=data[k]; i=l; j=m;
572 do {
573 while(data[i]<x) i++;
574 while(x<data[j]) j--;
575 if(i<=j) {s=data[i]; data[i]=data[j]; data[j]=s; i++; j--;}
576 } while(i<=j);
577 if(j<k) l=i;
578 if(k<i) m=j;
579 }
580 return(data[k]);
581}
Referenced by fmedian().
◆ fmean()
float fmean |
( |
float * | data, |
|
|
long long int | n, |
|
|
float * | sd ) |
Returns the mean in array data[0..n-1], and optionally calculates also the (sample) standard deviation of the mean.
- See also
- dmean, fmedian, mean, dmean_nan
- Returns
- Returns the mean in array data[0..n-1].
- Parameters
-
data | Pointer to data; data is not changed in any way. |
n | Length of data array. |
sd | Pointer to variable where SD will be written; enter NULL if not needed. |
Definition at line 618 of file imgminmax.c.
625 {
626 long long int i;
627 float sumsqr=0.0, sqrsum=0.0, avg;
628
629 if(n<1 || data==NULL) {if(sd!=NULL) *sd=0.0; return(0.0);}
630
631 for(i=0; i<n; i++) {sumsqr+=data[i]*data[i]; sqrsum+=data[i];}
632 avg=sqrsum/(float)n; if(sd==NULL) return(avg);
633 if(n==1) {
634 *sd=0.0;
635 } else {
636 sqrsum*=sqrsum;
637 *sd=sqrt( (sumsqr - sqrsum/(float)n) / (float)(n-1) );
638 }
639 return(avg);
640}
Referenced by imgBorderAverageTAC().
◆ fmedian()
float fmedian |
( |
float * | data, |
|
|
long long int | n ) |
Returns the median in array data[0..n-1].
Array is partially sorted. Algorithm is based on the book Wirth N. Algorithms + data structures = programs. Englewood Cliffs, Prentice-Hall, 1976.
- See also
- fMinMax, imgAvg, dmedian
- Returns
- Returns the median in array data[0..n-1].
- Parameters
-
data | Pointer to data; array is partially sorted |
n | Length of data array |
Definition at line 593 of file imgminmax.c.
598 {
599 long long int k;
600 float d1, d2;
601
602 if(n<1) return(0.0);
603 if(n%2) {
605 } else {
607 return(0.5*(d1+d2));
608 }
609}
float f_kth_smallest(float *data, long long int n, long long int k)
Referenced by imgBorderAverageTAC(), med21(), and med9().
◆ fMinMaxFin()
void fMinMaxFin |
( |
float * | data, |
|
|
long long int | n, |
|
|
float * | fmin, |
|
|
float * | fmax ) |
Finds the minimum and maximum value in a float array.
Only finite values are considered.
- See also
- imgMinMax, imgAbsMax, imgAvg
- Parameters
-
data | Pointer to float array of size n. |
n | Array length. |
fmin | Pointer to float value for minimum; enter NULL if not needed. |
fmax | Pointer to float value for maximum; enter NULL if not needed. |
Definition at line 649 of file imgminmax.c.
658 {
659 if(fmin!=NULL) *fmin=nanf("");
660 if(fmax!=NULL) *fmax=nanf("");
661
662 long long int i;
663 for(i=0; i<n; i++) if(isfinite(data[i])) break;
664 if(i==n) return;
665 float mi, ma;
666 mi=ma=data[i++];
667 for(; i<n; i++) if(isfinite(data[i])) {
668 if(data[i]>ma) ma=data[i];
669 else if(data[i]<mi) mi=data[i];
670 }
671 if(fmin!=NULL) *fmin=mi;
672 if(fmax!=NULL) *fmax=ma;
673 return;
674}
Referenced by ecat63WriteImageMatrix(), ecat63WriteScanMatrix(), ecat7Write2DScanMatrix(), ecat7WriteImageMatrix(), ecat7WritePolarmapMatrix(), ecat7WriteScanMatrix(), mrp(), and trmrp().
◆ imgAbsMax()
int imgAbsMax |
( |
IMG * | img, |
|
|
float * | maxvalue ) |
Searches the max absolute pixel value in the IMG data.
Sets maxvalue to the absolute max value with sign.
- See also
- imgFrameMinMax, imgMinMax, imgMax, imgSmoothMax
- Returns
- 0 if ok, 1 invalid image status, 2 invalid output pointer, 3 invalid image dimensions.
- Parameters
-
img | Pointer to IMG structure. |
maxvalue | Pointer to output. |
Definition at line 44 of file imgminmax.c.
49 {
51 if(maxvalue==NULL) return(2); else *maxvalue=0.0;
53 float f=nanf("");
54 for(
int pi=0; pi<img->
dimz; pi++)
55 for(
int yi=0; yi<img->
dimy; yi++)
56 for(
int xi=0; xi<img->
dimx; xi++)
57 for(
int fi=0; fi<img->
dimt; fi++) {
58 if(!isfinite(f) || fabs(img->
m[pi][yi][xi][fi])>fabs(f)) f=img->
m[pi][yi][xi][fi];
59 }
60 *maxvalue=f;
61 return(0);
62}
#define IMG_STATUS_OCCUPIED
◆ imgAvg()
Calculates average voxel value inside specified image range.
- See also
- imgMinMax, imgMax, fmedian, imgTimeIntegral
- Returns
- Returns 0 when successful.
- Parameters
-
img | Pointer to IMG image structure |
r | Pointer to range inside IMG; enter NULL if whole IMG is used |
avg | Target for mean value |
Definition at line 503 of file imgminmax.c.
510 {
511 int zi, yi, xi, fi;
512 long long n=0;
513
515 if(r!=NULL) {
516 if(r->
z1<1 || r->
y1<1 || r->
x1<1 || r->
f1<1)
return(2);
519 }
520 if(avg==NULL) return(5);
521
522 *avg=0.0;
523 if(r!=NULL) {
524 for(zi=r->
z1-1; zi<r->z2; zi++) {
525 for(yi=r->
y1-1; yi<r->y2; yi++) {
526 for(xi=r->
x1-1; xi<r->x2; xi++) {
527 for(fi=r->
f1-1; fi<r->f2; fi++)
if(!isnan(img->
m[zi][yi][xi][fi])) {
528 *avg+=img->
m[zi][yi][xi][fi]; n++;
529 }
530 }
531 }
532 }
533 } else {
534 for(zi=0; zi<img->
dimz; zi++) {
535 for(yi=0; yi<img->
dimy; yi++) {
536 for(xi=0; xi<img->
dimx; xi++) {
537 for(fi=0; fi<img->
dimt; fi++)
if(!isnan(img->
m[zi][yi][xi][fi])) {
538 *avg+=img->
m[zi][yi][xi][fi]; n++;
539 }
540 }
541 }
542 }
543 }
544 if(n>0) *avg/=(float)n;
545 return(0);
546}
◆ imgFrameMinMax()
int imgFrameMinMax |
( |
IMG * | img, |
|
|
int | frame, |
|
|
float * | minvalue, |
|
|
float * | maxvalue ) |
Searches the min and max pixel value in one frame (1..dimt) of the IMG data.
- Returns
- 0 if ok, 1 invalid image status, 2 invalid output pointer, 3 invalid image dimensions.
- See also
- imgMinMax, imgRangeMinMax, imgReadMinMax, imgGetMaxFrame
- Parameters
-
img | Pointer to IMG data. |
frame | Frame number [1..number of frames]. |
minvalue | Pointer to float value where minimum is written. |
maxvalue | Pointer to float value where maximum is written. |
Definition at line 171 of file imgminmax.c.
180 {
182 if(minvalue==NULL || maxvalue==NULL) return(2);
183 *minvalue=*maxvalue=0.0;
184 int fi=frame-1;
186 if(frame<1) return(4);
187
188 float mi, ma;
189 mi=ma=nanf("");
190 for(
int pi=0; pi<img->
dimz; pi++)
191 for(
int yi=0; yi<img->
dimy; yi++)
192 for(
int xi=0; xi<img->
dimx; xi++) {
193 if(!isfinite(ma) || img->
m[pi][yi][xi][fi]>ma) ma=img->
m[pi][yi][xi][fi];
194 if(!isfinite(mi) || img->
m[pi][yi][xi][fi]<mi) mi=img->
m[pi][yi][xi][fi];
195 }
196 *minvalue=mi; *maxvalue=ma;
197 if(!isfinite(mi) || !isfinite(ma)) return(5);
198 return(0);
199}
Referenced by img2svol().
◆ imgGetMaxFrame()
int imgGetMaxFrame |
( |
IMG * | img, |
|
|
IMG * | mimg, |
|
|
int | verbose ) |
Search the frame with maximum pixel value for each image pixel separately.
- See also
- imgGetPeak, imgGetMaxTime
- Returns
- Returns 0, if ok.
- Parameters
-
img | Image to search for max frames; not modified |
mimg | Pointer to empty IMG struct in which the nr of frame with max pixel value will be written; 0 is written if max value is <= 0; any old contents are deleted. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 454 of file imgminmax.c.
463 {
464 if(verbose>0) printf("imgGetMaxFrame()\n");
465
467 if(mimg==NULL) return(2);
469
470
471 int ret;
472 if(verbose>1) printf(
"allocating memory for %dx%dx%d pixels\n", img->
dimz, img->
dimy, img->
dimx);
474
478
479
480 int ti, zi, xi, yi;
481 double mv; int mi;
482 for(zi=0; zi<img->
dimz; zi++) {
483 for(yi=0; yi<img->
dimy; yi++)
for(xi=0; xi<img->
dimx; xi++) {
484 ti=mi=0; mv=img->
m[zi][yi][xi][ti];
485 for(ti=1; ti<img->
dimt; ti++) {
486 if(img->
m[zi][yi][xi][ti]<mv)
continue;
487 mi=ti; mv=img->
m[zi][yi][xi][ti];
488 }
489 if(mv>1.0E-008) mimg->
m[zi][yi][xi][0]=1.0+mi;
490 else mimg->
m[zi][yi][xi][0]=0.0;
491 }
492 }
493
494 return(0);
495}
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
int imgCopyhdr(IMG *image1, IMG *image2)
void imgEmpty(IMG *image)
◆ imgGetMaxTime()
int imgGetMaxTime |
( |
IMG * | img, |
|
|
IMG * | mimg, |
|
|
const int | w, |
|
|
int | verbose ) |
Search the time of maximum value for each image pixel separately.
- See also
- imgGetPeak, imgGetMaxFrame
- Returns
- Returns 0, if ok.
- Parameters
-
img | Image to search for max frames; not modified. |
mimg | Pointer to empty IMG struct in which the max time (sec) will be written; any old contents are deleted. |
w | Just save the frame middle time (0), or compute value weighted average time of all frames (1), or, value weighted average time of 3 or 5 subsequent frames (2). Option (1) uses the equation for mean residence time (MRT) for PTACs in pharmacokinetics. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout. |
Definition at line 345 of file imgminmax.c.
358 {
359 if(verbose>0) printf("imgGetMaxTime(*img, *mimg, %d)\n", w);
360
362 if(mimg==NULL) return(2);
364
365
366 int ret;
367 if(verbose>1) printf(
"allocating memory for %dx%dx%d pixels\n", img->
dimz, img->
dimy, img->
dimx);
369 if(ret) return(ret);
370
374 mimg->
unit=CUNIT_UNKNOWN;
375
376 if(w==0) {
377 for(
int zi=0; zi<img->
dimz; zi++) {
378 for(
int yi=0; yi<img->
dimy; yi++) {
379 for(
int xi=0; xi<img->
dimx; xi++) {
380
381 int ti=0, mi=0;
382 double mv=img->
m[zi][yi][xi][ti];
383 for(ti=1; ti<img->
dimt; ti++) {
384 if(img->
m[zi][yi][xi][ti]<mv)
continue;
385 mi=ti; mv=img->
m[zi][yi][xi][ti];
386 }
387 if(mv>0.0) mimg->
m[zi][yi][xi][0]=img->
mid[mi];
388 else mimg->
m[zi][yi][xi][0]=0.0;
389 }
390 }
391 }
392 return(0);
393 }
394
395 if(w==1) {
396 for(
int zi=0; zi<img->
dimz; zi++) {
397 for(
int yi=0; yi<img->
dimy; yi++) {
398 for(
int xi=0; xi<img->
dimx; xi++) {
399
400 double sumw=0.0, sumt=0.0;
401 for(
int ti=0; ti<img->
dimt; ti++) {
402 if(isnan(img->
m[zi][yi][xi][ti]))
continue;
403 float fdur=img->
end[ti]-img->
start[ti];
if(fdur<=0.0) fdur=1.0;
404 sumt+=img->
m[zi][yi][xi][ti]*img->
mid[ti]*fdur;
405 sumw+=img->
m[zi][yi][xi][ti]*fdur;
406 }
407 sumt/=sumw;
408 if(sumt>0.0 && sumw>0.0) mimg->
m[zi][yi][xi][0]=sumt;
409 else mimg->
m[zi][yi][xi][0]=0.0;
410 }
411 }
412 }
413 return(0);
414 }
415
416 if(w>1) {
417 for(
int zi=0; zi<img->
dimz; zi++) {
418 for(
int yi=0; yi<img->
dimy; yi++) {
419 for(
int xi=0; xi<img->
dimx; xi++) {
420
421 int ti=0, mi=0;
422 double mv=img->
m[zi][yi][xi][ti];
423 for(ti=1; ti<img->
dimt; ti++) {
424 if(img->
m[zi][yi][xi][ti]<mv)
continue;
425 mi=ti; mv=img->
m[zi][yi][xi][ti];
426 }
427
428 if(mi<1 || mi>img->
dimt-2)
continue;
429 int i1, i2; i1=mi-1; i2=mi+1; if(i1>0 && i2<img->dimt-1) {i1--; i2++;}
430 double sumw=0.0, sumt=0.0;
431 for(int i=i1; i<=i2; i++) {
432 if(!(img->
m[zi][yi][xi][i]>0.0))
continue;
433 sumt+=img->
m[zi][yi][xi][i]*img->
mid[i];
434 sumw+=img->
m[zi][yi][xi][i];
435 }
436 sumt/=sumw;
437 if(sumt>0.0) mimg->
m[zi][yi][xi][0]=sumt;
438 else mimg->
m[zi][yi][xi][0]=0.0;
439 }
440 }
441 }
442 return(0);
443 }
444
445 return(0);
446}
◆ imgGetPeak()
int imgGetPeak |
( |
IMG * | img, |
|
|
float | beforeTime, |
|
|
IMG_PIXEL * | p, |
|
|
int | verbose ) |
Searches the max pixel value in the IMG data, which occurs before specified time.
- See also
- imgGetMaxTime, imgGetMaxFrame
- Returns
- Returns 0 if successful.
- Parameters
-
img | Pointer to IMG struct |
beforeTime | Time (sec) after which max value is not searched |
p | Pointer to struct where max pixel position is written |
verbose | Verbose level; 0 if nothing is to be printed in stdout |
Definition at line 294 of file imgminmax.c.
303 {
304 int zi, yi, xi, fi, mf;
305 float f;
306
307 if(verbose>0) printf("imgGetPeak(img, %g, p, %d)\n", beforeTime, verbose);
309 if(p==NULL) return(2);
311 if(beforeTime<img->mid[0]) {
312 if(verbose>0) fprintf(stderr, "Error: invalid max search time setting.\n");
313 return(4);
314 }
315 f=nanf(
""); mf=img->
dimt; p->
x=p->
y=p->
z=p->
f=1;
316 for(zi=0; zi<img->
dimz; zi++) {
317 for(yi=0; yi<img->
dimy; yi++) {
318 for(xi=0; xi<img->
dimx; xi++) {
319 for(fi=0; fi<img->
dimt; fi++)
if(img->
mid[fi]<=beforeTime) {
320 if(!isfinite(img->
m[zi][yi][xi][fi]))
continue;
321 if(isfinite(f) && img->
m[zi][yi][xi][fi]<f)
322 continue;
323 if(isfinite(f) && img->
m[zi][yi][xi][fi]==f) {
324
325 if(fi>=mf) continue;
326 }
327 f=img->
m[zi][yi][xi][fi];
328 p->
x=xi+1; p->
y=yi+1; p->
z=zi+1; p->
f=fi+1;
329 mf=fi;
330 }
331 }
332 }
333 }
334 if(!isfinite(f)) return(5);
335 if(verbose>2) printf("maxval := %g\n", f);
336 return(0);
337}
◆ imgMax()
int imgMax |
( |
IMG * | img, |
|
|
float * | maxvalue ) |
Search the max pixel value in the IMG data.
- See also
- imgFrameMinMax, imgMinMax, imgSmoothMax, imgAvg
- Returns
- 0 if ok, 1 invalid image status, 2 invalid output pointer, 3 invalid image dimensions.
- Parameters
-
img | Pointer to IMG structure. |
maxvalue | Pointer to output. |
Definition at line 15 of file imgminmax.c.
20 {
22 if(maxvalue==NULL) return(2); else *maxvalue=0.0;
24 float f=nanf("");
25 for(
int pi=0; pi<img->
dimz; pi++)
26 for(
int yi=0; yi<img->
dimy; yi++)
27 for(
int xi=0; xi<img->
dimx; xi++)
28 for(
int fi=0; fi<img->
dimt; fi++) {
29 if(!isfinite(f) || img->
m[pi][yi][xi][fi]>f) f=img->
m[pi][yi][xi][fi];
30 }
31 *maxvalue=f;
32 return(0);
33}
Referenced by imgThresholding(), and imgThresholdingLowHigh().
◆ imgMinMax()
int imgMinMax |
( |
IMG * | img, |
|
|
float * | minvalue, |
|
|
float * | maxvalue ) |
Searches the min and max pixel value in the IMG data.
- See also
- imgFrameMinMax, imgRangeMinMax, imgReadMinMax
- Returns
- Returns 0 when successful.
- Parameters
-
img | Pointer to IMG struct from where min and pixels are searched. |
minvalue | Pointer to min pixel value; Enter NULL if not needed. |
maxvalue | Pointer to max pixel value; Enter NULL if not needed. |
Definition at line 154 of file imgminmax.c.
161 {
162 return (
imgRangeMinMax(img, NULL, NULL, maxvalue, NULL, minvalue));
163}
int imgRangeMinMax(IMG *img, IMG_RANGE *r, IMG_PIXEL *maxp, float *maxv, IMG_PIXEL *minp, float *minv)
Referenced by imgPVCRRL(), imgPVCRVC(), imgReadMinMax(), imgSetAnalyzeHeader(), imgWriteAnalyze(), and imgWriteNifti().
◆ imgRangeMinMax()
Finds max and/or min voxel inside specified image range.
- See also
- imgFrameMinMax, imgMinMax, imgAvg
- Returns
- 0 if ok, 1 invalid volume status, 2 invalid range endings, 3 inconsistent range dimensions, 4 inconsistent dimensions
- Parameters
-
img | Pointer to IMG structure. |
r | Pointer to image range inside IMG; enter NULL if whole IMG is used. |
maxp | Pixel where max pixel position is written; NULL if not needed. |
maxv | Target for max value; NULL if not needed. |
minp | Pixel where min pixel position is written; NULL if not needed. |
minv | Target for min value; NULL if not needed. |
Definition at line 71 of file imgminmax.c.
84 {
85 int zi, yi, xi, fi;
86 float lmax, lmin;
87
90
91 if(r!=NULL) {
92 if(r->
z1<1 || r->
y1<1 || r->
x1<1 || r->
f1<1)
return(2);
95
96 zi=r->
z1-1; yi=r->
y1-1; xi=r->
x1-1; fi=r->
f1-1;
97 lmax=lmin=nanf("");
98 if(maxp!=NULL) {maxp->
z=zi+1; maxp->
y=yi+1; maxp->
x=xi+1; maxp->
f=fi+1;}
99 if(minp!=NULL) {minp->
z=zi+1; minp->
y=yi+1; minp->
x=xi+1; minp->
f=fi+1;}
100 for(zi=r->
z1-1; zi<r->z2; zi++) {
101 for(yi=r->
y1-1; yi<r->y2; yi++) {
102 for(xi=r->
x1-1; xi<r->x2; xi++) {
103 for(fi=r->
f1-1; fi<r->f2; fi++) {
104 if(!isfinite(lmax) || img->
m[zi][yi][xi][fi]>lmax) {
105 lmax=img->
m[zi][yi][xi][fi];
106 if(maxp!=NULL && isfinite(img->
m[zi][yi][xi][fi])) {
107 maxp->
z=zi+1; maxp->
y=yi+1; maxp->
x=xi+1; maxp->
f=fi+1;}
108 }
109 if(!isfinite(lmin) || img->
m[zi][yi][xi][fi]<lmin) {
110 lmin=img->
m[zi][yi][xi][fi];
111 if(minp!=NULL && isfinite(img->
m[zi][yi][xi][fi])) {
112 minp->
z=zi+1; minp->
y=yi+1; minp->
x=xi+1; minp->
f=fi+1;}
113 }
114 }
115 }
116 }
117 }
118 } else {
119 zi=yi=xi=fi=0; lmax=lmin=nanf("");
120 if(maxp!=NULL) {maxp->
z=zi+1; maxp->
y=yi+1; maxp->
x=xi+1; maxp->
f=fi+1;}
121 if(minp!=NULL) {minp->
z=zi+1; minp->
y=yi+1; minp->
x=xi+1; minp->
f=fi+1;}
122 for(zi=0; zi<img->
dimz; zi++) {
123 for(yi=0; yi<img->
dimy; yi++) {
124 for(xi=0; xi<img->
dimx; xi++) {
125 for(fi=0; fi<img->
dimt; fi++) {
126 if(!isfinite(lmax) || img->
m[zi][yi][xi][fi]>lmax) {
127 lmax=img->
m[zi][yi][xi][fi];
128 if(maxp!=NULL && isfinite(img->
m[zi][yi][xi][fi])) {
129 maxp->
z=zi+1; maxp->
y=yi+1; maxp->
x=xi+1; maxp->
f=fi+1;}
130 }
131 if(!isfinite(lmin) || img->
m[zi][yi][xi][fi]<lmin) {
132 lmin=img->
m[zi][yi][xi][fi];
133 if(minp!=NULL && isfinite(img->
m[zi][yi][xi][fi])) {
134 minp->
z=zi+1; minp->
y=yi+1; minp->
x=xi+1; minp->
f=fi+1;}
135 }
136 }
137 }
138 }
139 }
140 }
141 if(maxv!=NULL) *maxv=lmax;
142 if(minv!=NULL) *minv=lmin;
143 if(!isfinite(lmax) && (maxp!=NULL || maxv!=NULL)) return(5);
144 if(!isfinite(lmin) && (minp!=NULL || minv!=NULL)) return(5);
145 return(0);
146}
Referenced by imgMinMax().
◆ imgReadMinMax()
int imgReadMinMax |
( |
const char * | fname, |
|
|
float * | fmin, |
|
|
float * | fmax ) |
Read the calibrated maximum and minimum pixel values in the specified file in ECAT 7, ECAT 6.3, or Analyze 7.5 format.
File is read frame-by-frame with normal IMG functions.
- See also
- imgFrameMinMax, imgRangeMinMax, imgMinMax
- Returns
- errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.
- Parameters
-
fname | ECAT 7 or ECAT 6.3 filename, or Analyze 7.5 database. |
fmin | Pointer to minimum pixel value that will be set by this function. |
fmax | Pointer to maximum pixel value that will be set by this function. |
Definition at line 211 of file imgminmax.c.
218 {
219 int fi=0, ret;
221 float frmin, frmax;
222
223 if(
IMG_TEST) printf(
"imgReadMinMax(%s, *fmin, *fmax)\n", fname);
227 if(fi==0) {
228 if(fmin!=NULL) *fmin=frmin;
229 if(fmin!=NULL) *fmax=frmax;
230 } else {
231 if(fmin!=NULL && !(*fmin<=frmin)) *fmin=frmin;
232 if(fmax!=NULL && !(*fmax>=frmax)) *fmax=frmax;
233 }
234 fi++;
235 }
237 if(ret==STATUS_NOMATRIX && fi>0) return STATUS_OK;
238 else return ret;
239}
int imgReadFrame(const char *fname, int frame_to_read, IMG *img, int frame_index)
int imgMinMax(IMG *img, float *minvalue, float *maxvalue)
◆ imgSmoothMax()
int imgSmoothMax |
( |
IMG * | img, |
|
|
float * | maxvalue, |
|
|
IMG_PIXEL * | p ) |
Searches the spatially (3x3) smoothed max pixel value in the IMG data.
- See also
- imgFrameMinMax, imgMinMax, imgMax, imgAbsMax, imgGetPeak
- Returns
- 0 if ok, 1 invalid image status, 2 invalid output pointer, 3 invalid image dimensions.
- Parameters
-
img | Pointer to IMG struct |
maxvalue | Pointer to float in which max pixel value will be written; enter NULL if not needed |
p | Pointer to struct in which the position of max pixel will be written (1-based positions); enter NULL if not needed |
Definition at line 248 of file imgminmax.c.
257 {
258 int pi, yi, xi, fi;
259 float f, v;
260
262 if(maxvalue==NULL && p==NULL) return(2);
264 if(maxvalue!=NULL) *maxvalue=0.0;
265 if(p!=NULL) p->
x=p->
y=p->
z=p->
f=1;
266 f=-1.0E20;
267 for(pi=0; pi<img->
dimz; pi++)
268 for(yi=1; yi<img->
dimy-1; yi++)
269 for(xi=1; xi<img->
dimx-1; xi++)
270 for(fi=0; fi<img->
dimt; fi++) {
271 v=img->
m[pi][yi-1][xi-1][fi]+
272 img->
m[pi][yi-1][xi ][fi]+
273 img->
m[pi][yi-1][xi+1][fi]+
274 img->
m[pi][yi ][xi-1][fi]+
275 img->
m[pi][yi ][xi ][fi]*2.0+
276 img->
m[pi][yi ][xi+1][fi]+
277 img->
m[pi][yi+1][xi-1][fi]+
278 img->
m[pi][yi+1][xi ][fi]+
279 img->
m[pi][yi+1][xi+1][fi];
280 v*=0.1;
281 if(v>f) {
282 f=v;
if(p!=NULL) {p->
x=xi+1; p->
y=yi+1; p->
z=pi+1; p->
f=fi+1;}}
283 }
284 if(maxvalue!=NULL) *maxvalue=f;
285 return(0);
286}