44 for ( i=n=0; n<p->
images(); n++ ) {
50 for ( j=0; j<imgsize; i++, j++ ) p->
set(i, (*ptemp)[j]);
77 cout <<
"Replacing maxima above: " << threshold << endl;
78 cout <<
"Number of maxima: " << pfeature->
maximum() << endl << endl;
80 cout <<
"Replacing maxima above: " << threshold << endl << endl;
82 if ( pfeature->
maximum() < 1 ) {
87 unsigned long i, j, k, m, n, x, y, z, iter;
88 long xx, yy, zz, nval, tx, ty, tz;
89 unsigned long nf = (
unsigned long) (pfeature->
maximum() + 1.5);
93 int* num =
new int[nf];
94 int* nimg =
new int[nf];
100 for ( j=1; j<nf; j++ ) {
101 min[j][0] = p->
sizeX();
102 min[j][1] = p->
sizeY();
103 min[j][2] = p->
sizeZ();
106 for ( i=n=0; n<p->
images(); n++ ) {
107 for ( z=0; z<p->
sizeZ(); z++ ) {
108 for ( y=0; y<p->
sizeY(); y++ ) {
109 for ( x=0; x<p->
sizeX(); x++, i++ ) {
110 j = (
unsigned long) (*pfeature)[i];
117 if ( min[j].x() > x ) min[j][0] = x;
118 if ( min[j].y() > y ) min[j][1] = y;
119 if ( min[j].z() > z ) min[j][2] = z;
120 if ( max[j].x() < x ) max[j][0] = x;
121 if ( max[j].y() < y ) max[j][1] = y;
122 if ( max[j].z() < z ) max[j][2] = z;
130 cout <<
"Features:\n#\tImage\tx\ty\tz\tSize" << endl;
131 for ( j=1; j<nf; j++ ) {
133 if ( num[j] ) feat[j] /= num[j];
135 cout << j <<
tab << n <<
tab << feat[j].
x() <<
tab << feat[j].
y() <<
tab << feat[j].
z() <<
tab << num[j] << endl;
136 min[j] = min[j].
max(0);
137 if ( max[j].x() >= p->
sizeX() ) max[j][0] = p->
sizeX() - 1;
138 if ( max[j].y() >= p->
sizeY() ) max[j][1] = p->
sizeY() - 1;
139 if ( max[j].z() >= p->
sizeZ() ) max[j][2] = p->
sizeZ() - 1;
140 feature_size[0] = max[j].
x() - min[j].
x() + 1;
141 feature_size[1] = max[j].
y() - min[j].
y() + 1;
142 feature_size[2] = max[j].
z() - min[j].
z() + 1;
143 temp =
new float[feature_size.
x()*feature_size.
y()*feature_size.
z()];
146 while ( nval < num[j] ) {
147 for ( k=0; k<feature_size.
volume(); k++ )
149 for ( z=min[j].z(); z<=max[j].
z(); z++ ) {
151 lo[2] = ( z > 0 )? z - 1: 0;
152 hi[2] = ( z < p->
sizeZ() - 1 )? z + 1: p->
sizeZ() - 1;
153 for ( y=min[j].y(); y<=max[j].
y(); y++ ) {
155 lo[1] = ( y > 0 )? y - 1: 0;
156 hi[1] = ( y < p->
sizeY() - 1 )? y + 1: p->
sizeY() - 1;
157 for ( x=min[j].x(); x<=max[j].
x(); x++ ) {
159 lo[0] = ( x > 0 )? x - 1: 0;
160 hi[0] = ( x < p->
sizeX() - 1 )? x + 1: p->
sizeX() - 1;
162 i = p->
index(0,x,y,z,n);
163 if ( (*pfeature)[i] == j ) {
166 for ( zz=lo.
z(); zz<=hi.
z(); zz++ ) {
167 for ( yy=lo.
y(); yy<=hi.
y(); yy++ ) {
168 for ( xx=lo.
x(); xx<=hi.
x(); xx++ ) {
170 k = p->
index(0,xx,yy,zz,n);
171 if ( (*pfeature)[k] < 1 ) {
179 k = (tz*feature_size.
y() + ty)*feature_size.
x() + tx;
186 for ( z=min[j].z(); z<=max[j].
z(); z++ ) {
188 for ( y=min[j].y(); y<=max[j].
y(); y++ ) {
190 for ( x=min[j].x(); x<=max[j].
x(); x++ ) {
193 i = p->
index(0,x,y,z,n);
194 k = (tz*feature_size.
y() + ty)*feature_size.
x() + tx;
195 if ( temp[k] > p->
minimum() ) {
197 if ( (*pfeature)[i] == j ) pfeature->
set(i, 0);
205 cout << iter <<
":\t" << nval << endl;
250 int target_num,
float threshold)
261 if ( threshold < p->average() ) sign = -1;
262 double abs_threshold = sign*threshold;
265 unsigned long i, x, y, z, n;
266 unsigned long count = 0;
268 int* feature_mask =
new int[datasize];
269 for ( i=0; i<datasize; i++ ) feature_mask[i] = 0;
272 cout <<
"Using the ";
273 switch ( extract_method ) {
274 case 1: cout <<
"center of mass ";
break;
275 case 2: cout <<
"center of volume ";
break;
276 case 3: cout <<
"highest pixel density ";
break;
277 default: cout <<
"center of mass ";
break;
279 cout <<
"to determine the feature coordinates in " << p->
file_name() << endl;
283 for ( i=0; i<datasize; i++ ) {
284 if ( sign*(*p)[i] > abs_threshold ) {
285 if ( feature_mask[i] == 0 ) {
294 cout <<
"Features extracted: " << count << endl << endl;
297 delete[] feature_mask;
305 for ( i=0; i<count; i++ ) {
313 for ( i=n=0; n<p->
images(); n++ ) {
314 for ( z=0; z<p->
sizeZ(); z++ ) {
315 for ( y=0; y<p->
sizeY(); y++ ) {
316 for ( x=0; x<p->
sizeX(); x++, i++ ) {
317 if ( feature_mask[i] > 0 ) {
318 m = lut[feature_mask[i]-1];
320 temp = fabs((*p)[i]);
321 if ( extract_method == 1 ) {
326 }
else if ( extract_method == 2 ) {
332 if ( sign*(*p)[i] > sign*m->
fom ) {
334 if ( extract_method == 3 ) {
347 delete[] feature_mask;
350 cout <<
"Feature marker list generated" << endl;
355 cout <<
"Feature\tx\ty\tz\tex\tey\tez\tFOM" << endl;
357 for ( m=set; m; m=m->
next ) {
358 if ( extract_method == 1 || extract_method == 2 )
371 cout <<
"\nDEBUG img_extract_features: The Feature set" << endl;
372 for ( m=set; m; m=m->
next )
373 cout <<
"Feature " << m->
id <<
": " << m->
loc <<
tab << m->
fom << endl;
412 if ( sign < 0 ) sign = -1;
413 else if ( sign > 0 ) sign = 1;
416 if ( threshold < p->average() ) sign = -1;
419 unsigned long i, count = 0;
420 float abs_threshold = sign*threshold;
423 cout <<
"DEBUG img_find_features: threshold=" << threshold <<
" sign=" << sign << endl;
433 for ( i=0; i<datasize; i++ ) {
434 if ( (*pfeature)[i] == 0 ) {
435 if ( sign*(*p)[i] > abs_threshold ) {
445 cout <<
"DEBUG img_find_features: Finished with " << count <<
" features" << endl;
457 unsigned long i, datasize = p->
data_size();
459 int nf = (int) (p->
maximum() + 1);
460 int* f =
new int[nf];
463 for ( i=0; i<nf; i++ ) f[i] = 0;
465 for ( i=0; i<datasize; i++ ) {
470 for ( i=0; i<nf; i++ )
if ( f[i] ) {
479 cout <<
"Number of regions: " << nr << endl;
480 cout <<
"Average region size: " << a << endl << endl;
498 x = i - y*p->
sizeX();
509 if ( lo.
z() < 0 ) lo[2] = 0;
510 if ( lo.
y() < 0 ) lo[1] = 0;
511 if ( lo.
x() < 0 ) lo[0] = 0;
512 if ( hi.
z() >= p->
sizeZ() ) hi[2] = p->
sizeZ() - 1;
513 if ( hi.
y() >= p->
sizeY() ) hi[1] = p->
sizeY() - 1;
514 if ( hi.
x() >= p->
sizeX() ) hi[0] = p->
sizeX() - 1;
518 cout <<
"DEBUG img_calc_kernel_limits: lo=" << lo <<
" hi=" << hi << endl;
544 int feature_number,
float threshold,
int sign,
int wrap)
547 cout <<
"DEBUG img_assignAllMyNeighbors: Starting with feature " <<
548 feature_number <<
" index=" << index << endl;
550 if ( sign < 0 ) sign = -1;
551 else if ( sign > 0 ) sign = 1;
554 if ( threshold < p->average() ) sign = -1;
557 float abs_threshold = sign*threshold;
558 unsigned long i, j, n, x, y, z;
565 unsigned long number, new_number;
568 int* list =
new int[list_size];
569 int* new_list =
new int[list_size];
572 feature_mask[index] = feature_number;
578 while ( number > 0 ) {
580 cout <<
"DEBUG img_assignAllMyNeighbors: Feature " << feature_number <<
" list size=" << number << endl;
582 for ( i=0; i<number; i++ ) {
586 for ( zz=lo.
z(); zz<=hi.
z(); zz++ ) {
589 if ( zz < 0 ) z = zz + (long)p->
sizeZ();
592 for ( yy=lo.
y(); yy<=hi.
y(); yy++ ) {
595 if ( yy < 0 ) y = yy + (long)p->
sizeY();
598 for ( xx=lo.
x(); xx<=hi.
x(); xx++ ) {
601 if ( xx < 0 ) x = xx + (long)p->
sizeX();
606 if ( (feature_mask[j] == 0) && (sign*(*p)[j] > abs_threshold) ) {
607 feature_mask[j] = feature_number;
608 new_list[new_number] = j;
610 if ( new_number >= list_size ) {
611 cerr <<
"Error: The list size exceeded its limit ("
612 << list_size <<
")" << endl;
620 for ( i=0; i<number; i++ ) list[i] = new_list[i];
627 cout <<
"DEBUG img_assignAllMyNeighbors: Ending with feature " << feature_number << endl;
void change_type(char letter)
Get the data type indicated by a single letter code.
int img_replace_maxima(Bimage *p, float threshold)
Replaces maxima above a threshold using local averages.
double img_average_feature_size(Bimage *p)
Calculates the average size of regions (features) in a level mask.
Header file for general utilities.
Header file for mask operation tools.
int img_assignAllMyNeighbors(Bimage *p, int *feature_mask, unsigned long index, int feature_number, float threshold, int sign, int wrap)
Finds all the pixels that are part of the same feature.
Bimage * mask_by_threshold(double threshold)
Generates a mask based on an image at a given threshold.
Bmarker * img_extract_features(Bimage *p, int extract_method, int target_num, float threshold)
Finds local minimums in a grey scale image and uses those as features.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
size_t index(size_t nx, size_t ny)
double average(size_t cc, double xf, double yf, double zf, size_t nn, double iscale)
Averages in the xy plane when scaling is less than 1.
size_t statistics()
Calculates the statistics for an image.
General image parameter class.
Header file for generalized linked list functions.
Bimage * img_find_features(Bimage *p, float threshold, int sign, int wrap)
Segments an image into contiguous regions (features).
int img_replace_maxima2(Bimage *p, float threshold)
long markers_limit(int target_num, int sign, Bmarker **set)
This method constricts a marker set to target_num points.
void file_name(Bstring s)
void set(size_t j, double v)
Sets a single value at the given index.
Bimage * extract(size_t nn)
Extracts one sub-image into new image structure.
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
unsigned char * data_pointer()
int img_calc_kernel_limits(Bimage *p, unsigned long index, Vector3< long > &lo, Vector3< long > &hi, int wrap)
Header file for feature extraction tools.
Header file for image parameter functions.
ostream & tab(ostream &out)