| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
img_fourier.cpp
Go to the documentation of this file.
1
11 #include "Bimage.h"
12 #include "img_fourier.h"
13 #include "Matrix.h"
14 #include "matrix_linear.h"
15 #include "math_util.h"
16 #include "trigonometry.h"
17 #include "timer.h"
18 #include "utilities.h"
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
23
24
25
45 Bimage* img_cross_correlate(Bimage* p1, Bimage* p2, double hires, double lores, Bimage* pmask)
46 {
47 if ( lores > 0 && hires > lores ) swap(hires, lores);
48
49 Bimage* pc = p1->pack_two_in_complex(p2);
50 if ( !pc ) return NULL;
51
52 // if ( hires < pc->sampling().x() ) hires = pc->sampling().x();
53
54 if ( verbose & VERB_FULL ) {
55 cout << "Cross-correlation:" << endl;
56 if ( lores > 0 || hires > 0 ) {
57 cout << "Resolution range: " << hires << " - ";
58 if ( lores > 0 ) cout << lores << " A" << endl;
59 else cout << "inf A" << endl;
60 } else
61 cout << "No resolution limits" << endl;
62 if ( pmask )
63 cout << "With a mask: " << pmask->file_name() << endl;
64 cout << endl;
65 }
66
67 pc->fft(FFTW_FORWARD, 0);
68
69 Complex<double> cv;
70 pc->set(0, cv);
71
72 pc->combined_complex_product(hires, lores, pmask);
73
74 pc->fft(FFTW_BACKWARD, 0);
75
76 pc->complex_to_real();
77
78 unsigned long n;
79 for ( n=0; n<pc->images(); n++ )
80 pc->image[n].origin(p1->image[n].origin() - p2->image[n].origin());
81
82 return pc;
83 }
84
85 Bimage* img_cross_correlate(Bimage* p1, Bimage* p2, double hires, double lores,
86 Bimage* pmask, fft_plan planf, fft_plan planb)
87 {
88 if ( lores > 0 && hires > lores ) swap(hires, lores);
89
90 Bimage* pc = p1->pack_two_in_complex(p2);
91 if ( !pc ) return NULL;
92
93 // if ( hires < pc->sampling().x() ) hires = pc->sampling().x();
94
95 if ( verbose & VERB_FULL ) {
96 cout << "Cross-correlation:" << endl;
97 if ( lores > 0 || hires > 0 ) {
98 cout << "Resolution range: " << hires << " - ";
99 if ( lores > 0 ) cout << lores << " A" << endl;
100 else cout << "inf A" << endl;
101 } else
102 cout << "No resolution limits" << endl;
103 if ( pmask )
104 cout << "With a mask: " << pmask->file_name() << endl;
105 cout << endl;
106 }
107
108 pc->fft(planf, 0);
109
110 Complex<double> cv;
111 pc->set(0, cv);
112
113 pc->combined_complex_product(hires, lores, pmask);
114
115 pc->fft(planb, 0);
116
117 pc->complex_to_real();
118
119 unsigned long n;
120 for ( n=0; n<pc->images(); n++ )
121 pc->image[n].origin(p1->image[n].origin() - p2->image[n].origin());
122
123 return pc;
124 }
125
126
154 int img_find_shift(Bimage* pref, Bimage* p, Bimage* pmask, double hires,
155 double lores, double radius, double sigma, int refine_flag)
156 {
157 if ( verbose & VERB_FULL ) {
158 if ( refine_flag )
159 cout << "Finding shift by cross-correlation and polynomial fitting" << endl << endl;
160 else
161 cout << "Finding shift by cross-correlation" << endl << endl;
162 }
163
164 Bimage* pc = img_cross_correlate(pref, p, hires, lores, pmask);
165 if ( !pc ) return -1;
166
167 if ( verbose & VERB_DEBUG )
168 write_img("cc.map", pc);
169
170 unsigned long n;
171 img_find_peak(pc, radius, sigma);
172
173 if ( refine_flag ) img_refine_peak(pc);
174
175 // Vector3<double> origin;
176
177 for ( n=0; n<pc->images(); n++ ) {
178 // origin = pc->image[n].origin();
179 // if ( origin.x() > pc->sizeX()/2 ) origin[0] -= pc->sizeX();
180 // if ( origin.y() > pc->sizeY()/2 ) origin[1] -= pc->sizeY();
181 // if ( origin.z() > pc->sizeZ()/2 ) origin[2] -= pc->sizeZ();
182 // pc->image[n].origin(origin);
183 p->image[n].origin(pref->image[n].origin() + pc->image[n].origin());
184 p->image[n].FOM(pc->image[n].FOM());
185 }
186
187 if ( verbose & VERB_FULL ) {
188 cout << "Image\t ox\t oy\t oz\t CC" << endl;
189 for ( n=0; n<p->images(); n++ )
190 cout << n+1 << tab << p->image[n].origin().x() << tab
191 << p->image[n].origin().y() << tab << p->image[n].origin().z()
192 << tab << p->image[n].FOM() << endl;
193 cout << endl;
194 }
195
196 delete pc;
197
198 return 0;
199 }
200
201 int img_find_shift(Bimage* pref, Bimage* p, Bimage* pmask, double hires,
202 double lores, double radius, double sigma, int refine_flag,
203 fft_plan planf, fft_plan planb)
204 {
205 if ( verbose & VERB_FULL ) {
206 if ( refine_flag )
207 cout << "Finding shift by cross-correlation and polynomial fitting" << endl << endl;
208 else
209 cout << "Finding shift by cross-correlation" << endl << endl;
210 }
211
212 Bimage* pc = img_cross_correlate(pref, p, hires, lores, pmask, planf, planb);
213 if ( !pc ) return -1;
214
215 if ( verbose & VERB_DEBUG )
216 write_img("cc.map", pc);
217
218 unsigned long n;
219 img_find_peak(pc, radius, sigma);
220
221 if ( refine_flag ) img_refine_peak(pc);
222
223 Vector3<double> origin;
224
225 for ( n=0; n<pc->images(); n++ ) {
226 origin = pc->image[n].origin();
227 if ( origin.x() > pc->sizeX()/2 ) origin[0] -= pc->sizeX();
228 if ( origin.y() > pc->sizeY()/2 ) origin[1] -= pc->sizeY();
229 if ( origin.z() > pc->sizeZ()/2 ) origin[2] -= pc->sizeZ();
230 pc->image[n].origin(origin);
231 p->image[n].origin(pref->image[n].origin() + pc->image[n].origin());
232 p->image[n].FOM(pc->image[n].FOM());
233 }
234
235 if ( verbose & VERB_FULL ) {
236 cout << "Image\t ox\t oy\t oz\t CC" << endl;
237 for ( n=0; n<p->images(); n++ )
238 cout << n+1 << tab << p->image[n].origin().x() << tab
239 << p->image[n].origin().y() << tab << p->image[n].origin().z()
240 << tab << p->image[n].FOM() << endl;
241 cout << endl;
242 }
243
244 delete pc;
245
246 return 0;
247 }
248
262 int img_find_peak(Bimage* p, double radius, double sigma)
263 {
264 if ( !p->data_pointer() ) return -1;
265
266 // cout << p->image->origin() << endl;
267
268 // p->information();
269 // write_img("cc.map", p);
270 // bexit(0);
271
272 if ( radius < 0 ) radius = 1e30;
273 else if ( radius < 1 ) radius = 0.9;
274 if ( sigma < 1e-30 ) sigma = 2e-30;
275
276 if ( verbose & VERB_DEBUG )
277 cout << "DEBUG img_find_peak: radius=" << radius << endl;
278
279 unsigned long i, n, x, y, z;
280 long xh = p->sizeX()/2, yh = p->sizeY()/2, zh = p->sizeZ()/2;
281 double x2, y2, z2, r;
282 double value, fac = GOLDEN/sigma;
283 Vector3<double> origin, peak;
284
285 if ( verbose & VERB_FULL ) {
286 cout << "Finding the brightest voxel" << endl;
287 cout << "n\tx\ty\tz\tv" << endl;
288 }
289
290 for ( i=n=0; n<p->images(); n++ ) {
291 if ( p->sizeX() > 1 ) origin[0] = p->image[n].origin().x();
292 if ( p->sizeY() > 1 ) origin[1] = p->image[n].origin().y();
293 if ( p->sizeZ() > 1 ) origin[2] = p->image[n].origin().z();
294 p->image[n].FOM(-1e37);
295 peak = origin;
296 for ( z=0; z<p->sizeZ(); z++ ) {
297 z2 = origin.z() - z;
298 if ( z2 < -zh ) z2 += p->sizeZ();
299 if ( z2 > zh ) z2 -= p->sizeZ();
300 z2 *= z2;
301 for ( y=0; y<p->sizeY(); y++ ) {
302 y2 = origin.y() - y;
303 if ( y2 < -yh ) y2 += p->sizeY();
304 if ( y2 > yh ) y2 -= p->sizeY();
305 y2 *= y2;
306 for ( x=0; x<p->sizeX(); x++, i++ ) {
307 x2 = origin.x() - x;
308 if ( x2 < -xh ) x2 += p->sizeX();
309 if ( x2 > xh ) x2 -= p->sizeX();
310 x2 *= x2;
311 r = sqrt(x2 + y2 + z2) - radius;
312 value = (*p)[i];
313 if ( sigma > 1e-30 ) value *= 1/(1 + exp(fac*r));
314 if ( p->image[n].FOM() < value ) {
315 p->image[n].FOM(value);
316 peak = Vector3<double>(x, y, z);
317 }
318 }
319 }
320 }
321 p->image[n].origin(peak);
322 // cout << "Peak=" << peak << endl;
323 if ( verbose & VERB_FULL )
324 cout << n+1 << tab << p->image[n].origin() << tab << p->image[n].FOM() << endl;
325 }
326 if ( verbose & VERB_FULL ) cout << endl;
327
328 return 0;
329 }
330
341 int img_refine_peak(Bimage* pc)
342 {
343 if ( !pc->data_pointer() ) return -1;
344
345 pc->change_type(Float);
346
347 size_t i, j, n, kernel_size(5), nterm(7);
348 long x, y, z, xlo, xhi, ylo, yhi, zlo, zhi, ix, iy, iz;
349 Vector3<long> int_shift;
350 Vector3<double> shift;
351 // double* a = new double[nterm*nterm];
352 Matrix a(nterm,nterm);
353 double* b = new double[nterm];
354 double* vec = new double[nterm];
355
356 Vector3<int> h(pc->size()/2);
357
358 if ( verbose & VERB_FULL ) {
359 cout << "Finding the shift in each image" << endl;
360 cout << "n\tx\ty\tz\tv" << endl;
361 }
362
363 for ( n=0; n<pc->images(); n++ ) {
364 shift = pc->image[n].origin();
365 int_shift[0] = (long) shift.x();
366 int_shift[1] = (long) shift.y();
367 int_shift[2] = (long) shift.z();
368 xlo = (long) (shift.x() - kernel_size);
369 xhi = (long) (shift.x() + kernel_size);
370 if ( xhi - xlo >= pc->sizeX() ) {
371 xlo = 0;
372 xhi = pc->sizeX() - 1;
373 }
374 ylo = (long) (shift.y() - kernel_size);
375 yhi = (long) (shift.y() + kernel_size);
376 if ( yhi - ylo >= pc->sizeY() ) {
377 ylo = 0;
378 yhi = pc->sizeY() - 1;
379 }
380 zlo = (long) (shift.z() - kernel_size);
381 zhi = (long) (shift.z() + kernel_size);
382 if ( zhi - zlo >= pc->sizeZ() ) {
383 zlo = 0;
384 zhi = pc->sizeZ() - 1;
385 }
386 if ( verbose & VERB_DEBUG )
387 cout << "DEBUG img_refine_peak: kernel limits = " <<
388 xlo << tab << xhi << tab << ylo << tab << yhi << tab << zlo << tab << zhi << endl;
389 for ( i=0; i<nterm; i++ ) { // Clear the matrix and vector
390 for ( j=0; j<nterm; j++ ) a[i][j] = 0;
391 b[i] = 0;
392 }
393 vec[0] = 1;
394 for ( z=zlo; z<=zhi; z++ ) {
395 iz = z;
396 if ( iz < 0 ) iz += pc->sizeZ();
397 if ( iz >= (long)pc->sizeZ() ) iz -= pc->sizeZ();
398 vec[3] = z;
399 vec[6] = z*z;
400 for ( y=ylo; y<=yhi; y++ ) {
401 iy = y;
402 if ( iy < 0 ) iy += pc->sizeY();
403 if ( iy >= (long)pc->sizeY() ) iy -= pc->sizeY();
404 vec[2] = y;
405 vec[5] = y*y;
406 for ( x=xlo; x<=xhi; x++ ) {
407 ix = x;
408 if ( ix < 0 ) ix += pc->sizeX();
409 if ( ix >= (long)pc->sizeX() ) ix -= pc->sizeX();
410 i = pc->index(0,ix,iy,iz,n);
411 vec[1] = x;
412 vec[4] = x*x;
413 if ( !isfinite((*pc)[i]) ) {
414 error_show("Error in img_refine_peak", __FILE__, __LINE__);
415 cerr << ix << " " << iy << " " << iz << " " << (*pc)[i] << endl;
416 return -9;
417 }
418 for ( j=0; j<nterm; j++ ) b[j] += vec[j]*(*pc)[i];
419 for ( i=0; i<nterm; i++ )
420 for ( j=0; j<=i; j++ ) a[i][j] += vec[i]*vec[j];
421 }
422 }
423 }
424 for ( i=0; i<nterm-1; i++ )
425 for ( j=i+1; j<nterm; j++ ) a[i][j] = a[j][i];
426 for ( i=0; i<nterm; i++ )
427 if ( fabs(a[i][i]) < 1e-37 ) a[i][i] = 1;
428 if ( verbose & VERB_DEBUG ) {
429 cout << "DEBUG img_refine_peak: Input matrix:" << endl;
430 // show_matrix(nterm, nterm, a);
431 cout << a;
432 cout << "DEBUG img_refine_peak: Input vector:";
433 for ( i=0; i<nterm; i++ ) cout << tab << b[i];
434 cout << endl;
435 }
436 // matrix_LU_decomposition(nterm, a, b);
437 a.LU_decomposition(b);
438 if ( verbose & VERB_DEBUG )
439 cout << "DEBUG img_refine_peak: Coefficients: " <<
440 b[0] << tab << b[1] << tab << b[2] << tab << b[3] << tab << b[4] << tab << b[5] << tab << b[6] << endl;
441 if ( b[4] ) shift[0] = -0.5*b[1]/b[4];
442 if ( b[5] ) shift[1] = -0.5*b[2]/b[5];
443 if ( b[6] ) shift[2] = -0.5*b[3]/b[6];
444 if ( fabs(int_shift.x() - shift.x()) > 2 ) shift[0] = int_shift.x();
445 if ( fabs(int_shift.y() - shift.y()) > 2 ) shift[1] = int_shift.y();
446 if ( fabs(int_shift.z() - shift.z()) > 2 ) shift[2] = int_shift.z();
447 // while ( shift.x() < -h.x() ) shift[0] += pc->sizeX(); // Ensures it is a proper shift
448 // while ( shift.y() < -h.y() ) shift[1] += pc->sizeY();
449 // while ( shift.z() < -h.z() ) shift[2] += pc->sizeZ();
450 // while ( shift.x() > h.x() ) shift[0] -= pc->sizeX();
451 // while ( shift.y() > h.y() ) shift[1] -= pc->sizeY();
452 // while ( shift.z() > h.z() ) shift[2] -= pc->sizeZ();
453 shift = vector3_origin_to_shift(shift, pc->size());
454 pc->image[n].origin(shift);
455 if ( verbose & VERB_FULL )
456 cout << n+1 << tab << shift.x() << tab << shift.y() << tab << shift.z() << endl;
457 }
458 if ( verbose & VERB_FULL ) cout << endl;
459
460 // delete[] a;
461 delete[] b;
462 delete[] vec;
463
464 return 0;
465 }
466
479 Bimage* img_phase_difference(Bimage* p1, Bimage* p2, double resolution_hi, double resolution_lo)
480 {
481 if ( resolution_hi <= 0 ) resolution_hi = 0.1;
482 if ( resolution_lo < resolution_hi + 1 ) resolution_lo = resolution_hi + 1;
483
484 Bimage* ppd = p1->pack_two_in_complex(p2);
485
486 ppd->fft();
487
488 // if ( verbose & VERB_FULL )
489 if ( verbose )
490 cout << "Cosine phase difference in the resolution range " << resolution_hi << " - " << resolution_lo << endl;
491
492 unsigned long i, j, x, y, z, n;
493 long ix, iy, iz;
494 unsigned long datasize = ppd->sizeX()*ppd->sizeY()*ppd->sizeZ()*ppd->images();
495 Vector3<float> shift;
496 double hires2 = 1.0/(resolution_hi*resolution_hi);
497 double lores2 = 1.0/(resolution_lo*resolution_lo);
498 double dy, dz, sx2, sy2, sz2, s2;
499 Vector3<double> scale(1.0/ppd->real_size());
500 Complex<float> temp1, temp2;
501
502 float* dphi = new float[datasize];
503
504 for ( n=0; n<ppd->images(); n++ ) {
505 ppd->image[n].origin(p1->image[n].origin() - p2->image[n].origin());
506 shift = ppd->image[n].origin()/ppd->size();
507 if ( verbose & VERB_FULL )
508 cout << n+1 << tab << shift.x() << tab << shift.y() << tab << shift.z() << endl;
509 for ( z=0; z<ppd->sizeZ(); z++ ) {
510 iz = -z;
511 if ( iz < 0 ) iz += ppd->sizeZ();
512 dz = z;
513 if ( z > (ppd->sizeZ() - 1)/2 ) dz -= ppd->sizeZ();
514 sz2 = dz*scale.z();
515 sz2 *= sz2;
516 for ( y=0; y<ppd->sizeY(); y++ ) {
517 iy = -y;
518 if ( iy < 0 ) iy += ppd->sizeY();
519 dy = y;
520 if ( y > (ppd->sizeY() - 1)/2 ) dy -= ppd->sizeY();
521 sy2 = dy*scale.y();
522 sy2 *= sy2;
523 for ( x=0; x<(ppd->sizeX()+1)/2; x++ ) {
524 ix = -x;
525 if ( ix < 0 ) ix += ppd->sizeX();
526 sx2 = x*scale.x();
527 sx2 *= sx2;
528 s2 = sx2 + sy2 + sz2;
529 if ( s2 >= lores2 && s2 <= hires2 ) {
530 i = ((n*ppd->sizeZ() + z)*ppd->sizeY() + y)*ppd->sizeX() + x;
531 j = ((n*ppd->sizeZ() + iz)*ppd->sizeY() + iy)*ppd->sizeX() + ix;
532 // i = ppd->index(0,x,y,z,n);
533 // j = ppd->index(0,ix,iy,iz,n);
534 // temp1 = complex_unpack_combined_first(ppd->complex(i), ppd->complex(j));
535 // temp2 = complex_unpack_combined_second(ppd->complex(i), ppd->complex(j));
536 temp1 = ppd->complex(i).unpack_first(ppd->complex(j));
537 temp2 = ppd->complex(i).unpack_second(ppd->complex(j));
538 dphi[i] = temp1.phi() - temp2.phi() - TWOPI*(x*shift.x() + y*shift.y() + z*shift.z());
539 // dphi[i] = batan2(data1.im,data1.re) - batan2(data2.im,data2.re);
540 // dphi[i] -= TWOPI*(x*shift.x() + y*shift.y() + z*shift.z());
541 dphi[j] = dphi[i] = bcos(dphi[i]);
542 }
543 }
544 }
545 }
546 }
547
548 ppd->data_type(Float);
549 ppd->compound_type(TSimple);
550 ppd->channels(1);
551 ppd->fourier_type(NoTransform);
552 ppd->data_assign((unsigned char *) dphi);
553
554 return ppd;
555 }
556
570 double img_average_phase_difference(Bimage* p1, Bimage* p2,
571 double resolution_hi, double resolution_lo, int weighting)
572 {
573 Bimage* ppd = p1->pack_two_in_complex(p2);
574
575 ppd->fft();
576
577 if ( resolution_hi <= 0 ) resolution_hi = 0.1;
578 if ( resolution_lo < resolution_hi + 1 ) resolution_lo = resolution_hi + 1;
579 if ( weighting < 0 ) weighting = 0;
580 if ( weighting > 3 ) weighting = 3;
581
582 unsigned long i, j, x, y, z, n;
583 long ix, iy, iz;
584 double hires2 = 1.0/(resolution_hi*resolution_hi);
585 double lores2 = 1.0/(resolution_lo*resolution_lo);
586 double dy, dz, sx2, sy2, sz2, szy2, szyx2, dphi, amp;
587 Vector3<double> scale(1.0/ppd->real_size());
588 Vector3<float> shift;
589 Complex<float> temp1, temp2;
590
591 double sum_amp = 0;
592 double avg_pd = 0;
593
594 for ( n=0; n<ppd->images(); n++ ) {
595 ppd->image[n].origin(p1->image[n].origin() - p2->image[n].origin());
596 shift = ppd->image[n].origin()/ppd->size();
597 for ( z=0; z<ppd->sizeZ(); z++ ) {
598 iz = -z;
599 if ( iz < 0 ) iz += ppd->sizeZ();
600 dz = z;
601 if ( z > (ppd->sizeZ() - 1)/2 ) dz -= ppd->sizeZ();
602 sz2 = dz*scale.z();
603 sz2 *= sz2;
604 if ( sz2 <= hires2 ) for ( y=0; y<ppd->sizeY(); y++ ) {
605 iy = -y;
606 if ( iy < 0 ) iy += ppd->sizeY();
607 dy = y;
608 if ( y > (ppd->sizeY() - 1)/2 ) dy -= ppd->sizeY();
609 sy2 = dy*scale.y();
610 sy2 *= sy2;
611 szy2 = sz2 + sy2;
612 if ( szy2 <= hires2 ) for ( x=0; x<(ppd->sizeX()+1)/2; x++ ) {
613 ix = -x;
614 if ( ix < 0 ) ix += ppd->sizeX();
615 sx2 = x*scale.x();
616 sx2 *= sx2;
617 szyx2 = szy2 + sx2;
618 if ( szyx2 <= hires2 && szyx2 >= lores2 ) {
619 i = ((n*ppd->sizeZ() + z)*ppd->sizeY() + y)*ppd->sizeX() + x;
620 j = ((n*ppd->sizeZ() + iz)*ppd->sizeY() + iy)*ppd->sizeX() + ix;
621 // i = ppd->index(0,x,y,z,n);
622 // j = ppd->index(0,ix,iy,iz,n);
623 // temp1 = complex_unpack_combined_first(ppd->complex(i), ppd->complex(j));
624 // temp2 = complex_unpack_combined_second(ppd->complex(i), ppd->complex(j));
625 temp1 = ppd->complex(i).unpack_first(ppd->complex(j));
626 temp2 = ppd->complex(i).unpack_second(ppd->complex(j));
627 dphi = temp1.phi() - temp2.phi() - TWOPI*(x*shift.x() + y*shift.y() + z*shift.z());
628 switch ( weighting ) {
629 case 1:
630 amp = temp1.amp();
631 break;
632 case 2:
633 amp = temp2.amp();
634 break;
635 case 3:
636 amp = temp1.amp() + temp2.amp();
637 break;
638 default:
639 amp = 1;
640 }
641 dphi = angle_set_negPI_to_PI(dphi);
642 sum_amp += amp;
643 // avg_pd += amp*dphi*dphi;
644 avg_pd += amp*fabs(dphi);
645 }
646 }
647 }
648 }
649 }
650
651 // if ( sum_amp ) avg_pd = sqrt(avg_pd/sum_amp);
652 if ( sum_amp ) avg_pd /= sum_amp;
653 else avg_pd = M_PI;
654
655 delete ppd;
656
657 return avg_pd;
658 }
659
666 int img_flip_phases(Bimage* p, Bimage* pd)
667 {
668 p->fft();
669
670 unsigned long i;
671 unsigned long datasize = p->sizeX()*p->sizeY()*p->sizeZ()*p->images();
672
673 for ( i=0; i<datasize; i++ )
674 if ( (*pd)[i] < 0 ) p->set(i, -p->complex(i));
675
676 p->fft_back();
677
678 return 0;
679 }
680
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1475
Vector3::z
Type z()
Definition: Vector3.h:141
Bimage::sizeZ
void sizeZ(size_t nz)
Definition: Bimage.h:311
Bimage.h
Header file for image class.
Bimage::combined_complex_product
int combined_complex_product()
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
Definition: Bimage_complex.cpp:735
bcos
double bcos(double x)
Avoid non-zero values for cos(PI/2) and cos(-PI/2).
Definition: trigonometry.cpp:27
Bimage::fft
int fft()
Definition: Bimage.h:642
Bimage::fft_back
int fft_back()
Definition: Bimage.h:643
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:105
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:562
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:286
GOLDEN
#define GOLDEN
Definition: utilities.h:74
Vector3< double >
error_show
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:684
Matrix.h
Generalized matrix class.
Bimage::index
size_t index(size_t nx, size_t ny) const
Definition: Bimage.h:315
img_average_phase_difference
double img_average_phase_difference(Bimage *p1, Bimage *p2, double resolution_hi, double resolution_lo, int weighting)
Calculates the average of the cosine of the phase difference between two images within given resoluti...
Definition: img_fourier.cpp:570
verbose
int verbose
img_phase_difference
Bimage * img_phase_difference(Bimage *p1, Bimage *p2, double resolution_hi, double resolution_lo)
Calculates the cosine of the phase difference between two images.
Definition: img_fourier.cpp:479
Bimage::size
Vector3< size_t > size() const
Definition: Bimage.h:306
img_flip_phases
int img_flip_phases(Bimage *p, Bimage *pd)
Flips the phases of an image based on a phase difference map.
Definition: img_fourier.cpp:666
vector3_origin_to_shift
Vector3< T1 > vector3_origin_to_shift(Vector3< T1 > origin, Vector3< T2 > size)
Definition: Vector3.h:302
img_refine_peak
int img_refine_peak(Bimage *pc)
Refines the position of a peak to sub-voxel resolution.
Definition: img_fourier.cpp:341
b
long b
Definition: jpegint.h:371
TSimple
Definition: Bimage.h:50
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:150
Bimage
General image parameter class.
Definition: Bimage.h:132
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:413
Matrix::LU_decomposition
double LU_decomposition()
Matrix inversion by LU decomposition.
Definition: matrix.cpp:60
M_PI
#define M_PI
Definition: utilities.h:52
Bimage::complex
Complex< double > complex(size_t j)
Returns a complex value at the given index.
Definition: Bimage.cpp:862
Bimage::channels
size_t channels()
Definition: Bimage.h:304
Bimage::data_assign
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
Definition: Bimage.cpp:623
Bsub_image::FOM
double FOM()
Definition: Bimage.h:122
img_fourier.h
General FFT for n-dimensional data.
Complex::amp
double amp()
Definition: Complex.h:104
Vector3::x
Type x()
Definition: Vector3.h:139
Bimage::file_name
void file_name(Bstring s)
Definition: Bimage.h:193
trigonometry.h
Header file for trigonometry functions.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:112
Bimage::set
void set(size_t j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:954
img_find_peak
int img_find_peak(Bimage *p, double radius, double sigma)
Finds the peak in an image to the nearest voxel.
Definition: img_fourier.cpp:262
write_img
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
Definition: rwimg.cpp:255
fftwnd_data
Definition: fftw.h:355
Bimage::complex_to_real
void complex_to_real()
The real part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:50
Bimage::images
size_t images()
Definition: Bimage.h:414
Complex
Definition: Complex.h:23
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:211
Matrix
Definition: Matrix.h:21
Bimage::sizeX
void sizeX(size_t nx)
Definition: Bimage.h:309
matrix_linear.h
Header file for matrix functions.
img_find_shift
int img_find_shift(Bimage *pref, Bimage *p, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Definition: img_fourier.cpp:154
FFTW_BACKWARD
Definition: fftw.h:64
Complex::phi
double phi()
Definition: Complex.h:105
Bimage::sizeY
void sizeY(size_t ny)
Definition: Bimage.h:310
NoTransform
Definition: Bimage.h:33
Bimage::pack_two_in_complex
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
Definition: Bimage_complex.cpp:600
FFTW_FORWARD
Definition: fftw.h:64
VERB_FULL
#define VERB_FULL
Definition: utilities.h:102
img_cross_correlate
Bimage * img_cross_correlate(Bimage *p1, Bimage *p2, double hires, double lores, Bimage *pmask)
Calculates a cross-correlation map by Fast Fourier transformation.
Definition: img_fourier.cpp:45
Bimage::data_type
DataType data_type()
Definition: Bimage.h:284
Vector3::y
Type y()
Definition: Vector3.h:140
TWOPI
#define TWOPI
Definition: utilities.h:61
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:300
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bimage::image
Bsub_image * image
Definition: Bimage.h:163
math_util.h
Header file for general utilities.