40 cout <<
"Calculating the complex product" << endl << endl;
71 cout <<
"Calculating the complex product" << endl << endl;
94 if ( !pmask )
return -1;
99 cout <<
"Masking a complex image" << endl;
104 for ( i=0; i<datasize; i++ )
105 if ( (*pmask)[i] <= 0 ) p->
set(i, cv);
124 if ( !pmask )
return -1;
129 cout <<
"Masking a complex image" << endl;
134 for ( i=0; i<datasize; i++ )
135 if ( (*pmask)[i] >= 0 ) p->
set(i, cv);
158 if ( !pmask )
return -1;
163 cout <<
"Masking a complex image with a dual mask" << endl;
171 for ( i=0; i<datasize; i++ ) {
172 if ( (*pmask)[i] <= 0 ) p->
set(i, cv);
173 if ( (*pmask)[i] >= 0 ) p2->
set(i, cv);
198 unsigned long i, n, x, y, z;
200 double sx2, sy2, sz2, s2;
202 if ( lores <= 0 ) lores = 1e30;
203 if ( hires <= 0 ) hires = 2*p->
sampling().x();
204 if ( lores < hires ) swap(lores, hires);
205 double s2hi = 1/(hires*hires);
206 double s2lo = 1/(lores*lores);
212 cout <<
"Bandpass limit to: " << 1/sqrt(s2hi) <<
" - " << 1/sqrt(s2lo) <<
" Å" << endl;
215 cout <<
"DEBUG img_complex_bandpass: hires=" << hires <<
" lores" << lores << endl;
217 for ( n=i=0; n<p->
images(); n++ ) {
218 for ( z=0; z<p->
sizeZ(); z++ ) {
220 if ( z > h.
z() ) zz -= p->
sizeZ();
223 for ( y=0; y<p->
sizeY(); y++ ) {
225 if ( y > h.
y() ) yy -= p->
sizeY();
228 for ( x=0; x<p->
sizeX(); x++, i++ ) {
230 if ( x > h.
x() ) xx -= p->
sizeX();
233 s2 = sx2 + sy2 + sz2;
234 if ( s2 > s2hi || s2 < s2lo ) p->
set(i, cv);
258 error_show(
"Error in img_pack_two_in_complex", __FILE__, __LINE__);
259 cerr <<
"No data for " << p1->
file_name() << endl;
264 error_show(
"Error in img_pack_two_in_complex", __FILE__, __LINE__);
265 cerr <<
"No data for " << p2->
file_name() << endl;
270 error_show(
"Error in img_pack_two_in_complex", __FILE__, __LINE__);
271 cerr <<
"Data for " << p1->
file_name() <<
" may not be compound!" << endl;
276 error_show(
"Error in img_pack_two_in_complex", __FILE__, __LINE__);
277 cerr <<
"Data for " << p2->
file_name() <<
" may not be compound!" << endl;
288 error_show(
"img_pack_two_in_complex", __FILE__, __LINE__);
297 cout <<
"Packing two real images into a complex image" << endl;
299 unsigned long datasize = p1->
data_size();
301 for ( i=j=0; i<datasize; i++ ) {
302 p->
set(j++, (*p1)[i]);
303 p->
set(j++, (*p2)[i]);
338 unsigned long i, j, x, y, z, n, xh = p->
sizeX()/2 + 1;
339 unsigned long ix, iy, iz;
349 cout <<
"Unpacking a combined Fourier transform" << endl << endl;
351 for ( n=0; n<p->
images(); n++ ) {
352 for ( z=0; z<p->
sizeZ(); z++ ) {
353 iz = (z>0)? p->
sizeZ() - z: 0;
354 for ( y=0; y<p->
sizeY(); y++ ) {
355 iy = (y>0)? p->
sizeY() - y: 0;
356 for ( x=0; x<xh; x++ ) {
357 ix = (x>0)? p->
sizeX() - x: 0;
360 if ( y > h.y() ) use = 0;
361 if ( y == iy && z > h.z() ) use = 0;
364 i = p->
index(x, y, z, n);
365 j = p->
index(ix, iy, iz, n);
369 p->
set(j, temp1.conj());
371 p2->
set(j, temp2.conj());
413 unsigned long i, j, n, x, y, z, xh = p->
sizeX()/2 + 1;
414 unsigned long ix, iy, iz;
418 double scale = 1, sum1, sum2;
422 cout <<
"Calculating the complex conjugate product" << endl;
425 cout <<
"DEBUG img_combined_complex_product: F0=" << p->
complex(0).real() <<
" " << p->
complex(0).imag() << endl;
429 for ( n=0; n<p->
images(); n++ ) {
431 for ( z=0; z<p->
sizeZ(); z++ ) {
432 iz = (z>0)? p->
sizeZ() - z: 0;
433 for ( y=0; y<p->
sizeY(); y++ ) {
434 iy = (y>0)? p->
sizeY() - y: 0;
435 for ( x=0; x<xh; x++ ) {
436 ix = (x>0)? p->
sizeX() - x: 0;
439 if ( y > h.y() ) use = 0;
440 if ( y == iy && z > h.z() ) use = 0;
443 i = p->
index(x, y, z, n);
444 j = p->
index(ix, iy, iz, n);
447 p->
set(i, temp1 * temp2.
conj());
449 sum1 += temp1.
power();
450 sum2 += temp2.
power();
456 scale = 0.5/sqrt(sum1*sum2);
461 if ( !isfinite(scale) ) {
462 error_show(
"Error in img_combined_complex_product", __FILE__, __LINE__);
463 cerr <<
"Scale not finite = " << scale << endl;
469 cout <<
"CC time: " << tvf - tvs << endl;
507 unsigned long i, j, n, x, y, z, xh = p->
sizeX()/2 + 1;
508 unsigned long ix, iy, iz;
513 double scale = 1, sum1, sum2;
517 cout <<
"Calculating the masked complex conjugate product" << endl;
520 cout <<
"DEBUG img_combined_masked_complex_product: F0 = " << p->
complex(0).real() <<
" " << p->
complex(0).imag() << endl;
523 for ( n=0; n<p->
images(); n++ ) {
525 for ( z=0; z<p->
sizeZ(); z++ ) {
526 iz = (z>0)? p->
sizeZ() - z: 0;
527 for ( y=0; y<p->
sizeY(); y++ ) {
528 iy = (y>0)? p->
sizeY() - y: 0;
529 for ( x=0; x<xh; x++ ) {
530 ix = (x>0)? p->
sizeX() - x: 0;
533 if ( y > h.y() ) use = 0;
534 if ( y == iy && z > h.z() ) use = 0;
537 i = p->
index(x, y, z, n);
538 j = p->
index(ix, iy, iz, n);
539 if ( (*pmask)[i] > 0 ) {
542 p->
set(i, temp1 * temp2.
conj());
544 sum1 += temp1.
power();
545 sum2 += temp2.
power();
555 scale = 0.5/sqrt(sum1*sum2);
560 if ( !isfinite(scale) ) {
561 error_show(
"Error in img_combined_bandpass_complex_product", __FILE__, __LINE__);
562 cerr <<
"Scale not finite = " << scale << endl;
598 unsigned long i, j,n, x, y, z, xh = p->
sizeX()/2 + 1;
599 unsigned long ix, iy, iz;
601 double sx2, sy2, sz2, s2;
603 if ( hires <= 0 ) hires = p->
sampling().x();
604 if ( lores > 0 && lores < hires ) swap(lores, hires);
605 double s2hi = 1/(hires*hires);
606 double s2lo = (lores > 0)? 1/(lores*lores): 0;
612 cout <<
"Calculating the complex conjugate product" << endl;
613 cout <<
"Resolution range: " << 1/sqrt(s2hi) <<
" - ";
614 if ( lores > 0 ) cout << 1/sqrt(s2lo) <<
" A" << endl;
615 else cout <<
"inf A" << endl;
619 double scale = 1, sum1, sum2;
623 cout <<
"DEBUG img_combined_bandpass_complex_product: F0 = " << p->
complex(0).real() <<
" " << p->
complex(0).imag() << endl;
627 for ( n=0; n<p->
images(); n++ ) {
629 for ( z=0; z<p->
sizeZ(); z++ ) {
631 if ( z > h.z() ) zz -= p->
sizeZ();
632 iz = (z>0)? p->
sizeZ() - z: 0;
635 for ( y=0; y<p->
sizeY(); y++ ) {
637 if ( y > h.y() ) yy -= p->
sizeY();
638 iy = (y>0)? p->
sizeY() - y: 0;
641 for ( x=0; x<xh; x++ ) {
642 ix = (x>0)? p->
sizeX() - x: 0;
645 if ( y > h.y() ) use = 0;
646 if ( y == iy && z > h.z() ) use = 0;
650 if ( x > h.x() ) xx -= p->
sizeX();
653 i = p->
index(x, y, z, n);
654 j = p->
index(ix, iy, iz, n);
655 s2 = sx2 + sy2 + sz2;
656 if ( s2 >= s2lo && s2 <= s2hi ) {
659 p->
set(i, temp1 * temp2.
conj());
661 sum1 += temp1.
power();
662 sum2 += temp2.
power();
672 scale = 0.5/sqrt(sum1*sum2);
677 if ( !isfinite(scale) ) {
678 error_show(
"Error in img_combined_bandpass_complex_product", __FILE__, __LINE__);
679 cerr <<
"Scale not finite = " << scale << endl;
685 cout <<
"CC(BP) time: " << tvf - tvs << endl;
723 unsigned long i, j,n, x, y, z, xh = p->
sizeX()/2 + 1;
724 unsigned long ix, iy, iz;
726 double sx2, sy2, sz2, s2;
728 if ( hires <= 0 ) hires = p->
sampling().x();
729 if ( lores > 0 && lores < hires ) swap(lores, hires);
730 double s2hi = 1/(hires*hires);
731 double s2lo = (lores > 0)? 1/(lores*lores): 0;
737 cout <<
"Calculating the masked and bandpassed complex conjugate product" << endl;
738 cout <<
"Resolution range: " << 1/sqrt(s2hi) <<
" - ";
739 if ( lores > 0 ) cout << 1/sqrt(s2lo) <<
" A" << endl;
740 else cout <<
"inf A" << endl;
744 double scale = 1, sum1, sum2;
748 cout <<
"DEBUG img_combined_bandpass_masked_complex_product: F0 = " << p->
complex(0).real() <<
" " << p->
complex(0).imag() << endl;
752 for ( n=0; n<p->
images(); n++ ) {
754 for ( z=0; z<p->
sizeZ(); z++ ) {
756 if ( z > h.z() ) zz -= p->
sizeZ();
757 iz = (z>0)? p->
sizeZ() - z: 0;
760 for ( y=0; y<p->
sizeY(); y++ ) {
762 if ( y > h.y() ) yy -= p->
sizeY();
763 iy = (y>0)? p->
sizeY() - y: 0;
766 for ( x=0; x<xh; x++ ) {
767 ix = (x>0)? p->
sizeX() - x: 0;
770 if ( y > h.y() ) use = 0;
771 if ( y == iy && z > h.z() ) use = 0;
775 if ( x > h.x() ) xx -= p->
sizeX();
778 i = p->
index(x, y, z, n);
779 j = p->
index(ix, iy, iz, n);
780 s2 = sx2 + sy2 + sz2;
781 if ( (*pmask)[i] <= 0 ) use = 0;
782 if ( s2 < s2lo || s2 > s2hi ) use = 0;
786 p->
set(i, temp1 * temp2.
conj());
788 sum1 += temp1.
power();
789 sum2 += temp2.
power();
799 scale = 0.5/sqrt(sum1*sum2);
804 if ( !isfinite(scale) ) {
805 error_show(
"Error in img_combined_bandpass_masked_complex_product", __FILE__, __LINE__);
806 cerr <<
"Scale not finite = " << scale << endl;
812 cout <<
"CC(BP) time: " << tvf - tvs << endl;
833 if ( !pamp )
return -1;
842 cout <<
"Merging amplitudes and phases" << endl << endl;
845 double a, ar, d, R = 0;
848 for ( i=0; i<datasize; i++ ) {
852 else ar = (pamp->
complex(i)).amp();
859 R = sqrt(R/datasize);
882 if ( !pref )
return -1;
885 cerr <<
"Error: The reference map must be a Fourier transform!" << endl << endl;
893 if ( res_hi < p->sampling().x() ) res_hi = p->
sampling().x();
894 if ( res_lo < res_hi ) res_lo = res_hi;
897 cout <<
"Merging amplitudes and phases in the range " << res_hi <<
" - " << res_lo <<
" Å" << endl << endl;
901 if ( maxrad < minrad + 1 ) maxrad = minrad + 1;
902 double minrad2 = minrad*minrad, maxrad2 = maxrad*maxrad;
904 unsigned long i, n, x, y, z, na(0);
905 double x2, y2, z2, r2;
908 double a, ar, d, R(0);
911 for ( i=n=0; n<p->
images(); n++ ) {
912 for ( z=0; z<p->
sizeZ(); z++ ) {
914 if ( z > h.
z() ) z2 -= p->
sizeZ();
916 for ( y=0; y<p->
sizeY(); y++ ) {
918 if ( y > h.
y() ) y2 -= p->
sizeY();
920 for ( x=0; x<p->
sizeX(); x++, i++ ) {
922 if ( x > h.
x() ) x2 -= p->
sizeX();
926 if ( r2 > maxrad2 ) {
928 }
else if ( r2 < minrad2 ) {
944 if ( na ) R = sqrt(R/na);
947 cout <<
"DEBUG img_merge_amplitudes_and_phases: minrad=" << minrad
948 <<
" maxrad=" << maxrad <<
" n=" << n <<
" R" << R << endl;
void change_type(char letter)
Get the data type indicated by a single letter code.
int img_combined_bandpass_masked_complex_product(Bimage *p, float hires, float lores, Bimage *pmask)
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
Header file for general utilities.
CompoundType compound_type()
Bimage * img_unpack_combined_transform(Bimage *p)
Unpacks a complex transform obtained from two real images.
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
void check()
Checks an image for reasonable properties.
double getwalltime()
Returns the current time.
size_t index(size_t nx, size_t ny)
size_t statistics()
Calculates the statistics for an image.
Functions to handle complex data sets.
Utilities for timing functions.
Functions to handle RGB images.
General image parameter class.
Vector3< double > real_size()
int img_complex_conjugate_product(Bimage *p, Bimage *p2)
Calculates the product of a complex image with the conjugate of a second.
int img_complex_apply_dual_mask(Bimage *p, Bimage *pmask)
Applies a dual mask to a complex image.
Complex< double > complex(size_t j)
Returns a complex value at the given index.
void multiply(size_t j, Complex< double > cv)
int img_complex_bandpass(Bimage *p, float hires, float lores)
Bandpasses a Fourier transform.
int img_combined_complex_product(Bimage *p)
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
int img_complex_apply_negative_mask(Bimage *p, Bimage *pmask)
Applies a mask to a complex image.
void file_name(Bstring s)
int img_complex_product(Bimage *p, Bimage *p2)
Calculates the complex product of two complex images.
int img_combined_bandpass_complex_product(Bimage *p, float hires, float lores)
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
void set(size_t j, double v)
Sets a single value at the given index.
double standard_deviation()
unsigned char * data_pointer()
Bimage * copy()
Copies the header information and data of an image into a new image structure.
int img_complex_apply_mask(Bimage *p, Bimage *pmask)
Applies a mask to a complex image.
int img_combined_masked_complex_product(Bimage *p, Bimage *pmask)
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
double img_merge_amplitudes_and_phases(Bimage *pamp, Bimage *p)
Merges the amplitudes from one map with the phases of another.
Bimage * img_pack_two_in_complex(Bimage *p1, Bimage *p2)
Packs two real images into one complex image.
bool check_if_same_size(Bimage *p)
Check if two images are the same size.
Header file for 2D and 3D image I/O.
FourierType fourier_type()