33 unsigned long i, n, x, y, z, nm;
34 double x2(0), y2(0), z2(0);
35 double hx = (p->
sizeX() - 1)/2.0;
36 double hy = (p->
sizeY() - 1)/2.0;
37 double hz = (p->
sizeZ() - 1)/2.0;
38 double ox = p->
sizeX()/2;
39 double oy = p->
sizeY()/2;
40 double oz = p->
sizeZ()/2;
43 cout <<
"Calculating a background mask" << endl << endl;
45 for ( i=n=0; n<p->
images(); n++ ) {
50 for ( z=0; z<p->
sizeZ(); z++ ) {
51 if ( p->
sizeZ() > 1 ) {
55 for ( y=0; y<p->
sizeY(); y++ ) {
56 if ( p->
sizeY() > 1 ) {
60 for ( x=0; x<p->
sizeX(); x++, i++ ) {
61 if ( p->
sizeX() > 1 ) {
65 if ( x2 + y2 + z2 > 1 ) {
73 cout <<
"DEBUG img_background_mask: img=" << n <<
" nm=" << nm << endl;
95 unsigned long i, j, x, y, z, c, nm(0);
96 double x2(0), y2(0), z2(0);
98 double hx = (p->
sizeX() - 1)/2.0;
99 double hy = (p->
sizeY() - 1)/2.0;
100 double hz = (p->
sizeZ() - 1)/2.0;
101 double ox = p->
sizeX()/2;
102 double oy = p->
sizeY()/2;
103 double oz = p->
sizeZ()/2;
110 for ( z=0; z<p->
sizeZ(); z++ ) {
111 if ( p->
sizeZ() > 1 ) {
115 for ( y=0; y<p->
sizeY(); y++ ) {
116 if ( p->
sizeY() > 1 ) {
120 for ( x=0; x<p->
sizeX(); x++, i++ ) {
121 if ( p->
sizeX() > 1 ) {
125 if ( x2 + y2 + z2 > 1 ) {
127 for ( c=0; c<p->
channels(); c++, j++ ) {
128 background += (*p)[j];
139 cout <<
"DEBUG img_calculate_background: img=" << n <<
" nm=" << nm << endl;
160 cout <<
"Calculating the background values of all images" << endl << endl;
163 dispatch_apply(p->
images(), dispatch_get_global_queue(0, 0), ^(
size_t n){
167 #pragma omp parallel for
168 for (
int n=0; n<p->
images(); n++ )
192 if ( !pmask )
return -1;
196 unsigned long i, j, k, c, nm(0);
197 double background(0);
200 for ( k=0; k<p->
size().
volume(); k++, i++ )
if ( (*pmask)[i] < 0.5 ) {
202 for ( c=0; c<p->
channels(); c++, j++ ) background += (*p)[j];
209 cout <<
"DEBUG img_calculate_background: img=" << n <<
" nm=" << nm <<
" bkg=" << p->
image[n].
background() << endl;
231 if ( !pmask )
return -1;
236 cout <<
"Calculating the background values of all images" << endl << endl;
239 dispatch_apply(p->
images(), dispatch_get_global_queue(0, 0), ^(
size_t n){
243 #pragma omp parallel for
244 for (
int n=0; n<p->
images(); n++ )
269 unsigned long i, j, x, y, z, c;
270 double x2(0), y2(0), z2(0);
272 double hx = (p->
sizeX() - 1)/2.0;
273 double hy = (p->
sizeY() - 1)/2.0;
274 double hz = (p->
sizeZ() - 1)/2.0;
275 double ox = p->
sizeX()/2;
276 double oy = p->
sizeY()/2;
277 double oz = p->
sizeZ()/2;
284 for ( z=0; z<p->
sizeZ(); z++ ) {
285 if ( p->
sizeZ() > 1 ) {
289 for ( y=0; y<p->
sizeY(); y++ ) {
290 if ( p->
sizeY() > 1 ) {
294 for ( x=0; x<p->
sizeX(); x++, i++ ) {
295 if ( p->
sizeX() > 1 ) {
299 if ( x2 + y2 + z2 > 1 ) {
301 for ( c=0; c<p->
channels(); c++, j++ )
302 p->
set(j, background);
309 cout <<
"DEBUG img_correct_background: img=" << n <<
" bkg=" << background << endl;
331 cout <<
"Correcting the background values of all images" << endl << endl;
334 dispatch_apply(p->
images(), dispatch_get_global_queue(0, 0), ^(
size_t n){
338 #pragma omp parallel for
339 for (
int n=0; n<p->
images(); n++ )
344 cerr <<
tab <<
"in img_correct_background" << endl;
366 if ( !pmask )
return -1;
372 unsigned long i, j, k, n, c, nm;
376 cout <<
"Correcting the background values of all images" << endl << endl;
378 for ( i=n=0; n<p->
images(); n++ ) {
381 for ( k=0; k<p->
size().
volume(); k++, i++ )
if ( (*pmask)[i] < 0.5 ) {
383 for ( c=0; c<p->
channels(); c++, j++ ) p->
set(j, background);
389 cerr <<
tab <<
"in img_correct_background" << endl;
424 unsigned long i, j, n;
425 double background, v;
429 cout <<
"Subtracting the background values of all images" << endl << endl;
434 for ( n=i=0; n<p->
images(); n++ ) {
436 for ( j=0; j<imagesize; i++, j++ ) {
440 if ( v < min ) v = min;
441 if ( v > max ) v = max;
446 if ( cv.
real() < min ) cv.
real(min);
447 if ( cv.
real() > max ) cv.
real(max);
448 if ( cv.
imag() < min ) cv.
imag(min);
449 if ( cv.
imag() > max ) cv.
imag(max);
456 cerr <<
tab <<
"in img_subtract_background2" << endl;
487 cout <<
"Shifting the background values of all images to " << background << endl;
489 for ( n=i=0; n<p->
images(); n++ ) {
492 for ( j=0; j<imagesize; i++, j++ ) {
496 if ( v < min ) v = min;
497 if ( v > max ) v = max;
502 if ( cv.
real() < min ) cv.
real(min);
503 if ( cv.
real() > max ) cv.
real(max);
504 if ( cv.
imag() < min ) cv.
imag(min);
505 if ( cv.
imag() > max ) cv.
imag(max);
512 cerr <<
tab <<
"in img_shift_background" << endl;
Complex< double > complex(unsigned long j)
Returns a complex value at the given index.
void sizeX(unsigned long nx)
Header file for general utilities.
int img_subtract_background2(Bimage *p)
Subtracts the background for each sub-image.
CompoundType compound_type()
Class for complex numbers.
int img_subtract_background(Bimage *p)
Subtracts the background for each sub-image.
Generalized matrix class.
int img_shift_background(Bimage *p, double background)
Sets the background for each sub-image to a given value.
size_t statistics()
Calculates the statistics for an image.
double data_type_max()
Get the maximum of a datatype.
General image parameter class.
Bimage * img_background_mask(Bimage *p)
Calculates a background mask.
void set(unsigned long j, double v)
Sets a single value at the given index.
void origin(double x, double y, double z)
int img_correct_background(Bimage *p, int n)
Corrects the background for one sub-image.
unsigned char * data_pointer()
Header file for manipulating image backgrounds.
void sizeZ(unsigned long nz)
int img_calculate_background(Bimage *p, int n)
Calculates the background for one sub-image.
Header file for 2D and 3D image I/O.
void sizeY(unsigned long ny)
double data_type_min()
Get the minimum of a datatype.
ostream & tab(ostream &out)