| Bsoft 2.0.5 Bernard's software package

Bimage_edit.cpp
Go to the documentation of this file.
1
9 #include "Bimage.h"
10 #include "matrix_linear.h"
11 #include "utilities.h"
12
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15
16
17 double rectangle_edge(Vector3<double> d, Vector3<double> hr)
18 {
19 d = d.abs() - hr;
20
21 if ( hr[2] > 1 && d[1] < d[2] ) d[1] = d[2];
22 if ( hr[1] > 1 && d[0] < d[1] ) d[0] = d[1];
23
24 return d[0];
25 }
26
27 double oval_edge(Vector3<double> d, Vector3<double> hr)
28 {
29 double f(0);
30
31 Vector3<double> de(d/hr);
32 double ld(d.length());
33
34 if ( ld < 1 ) return -100;
35
36 double lde(de.length());
37
38 if ( lde > 1e-20 )
39 f = ld*(1.0 - 1.0/lde);
40
41 return f;
42 }
43
44 double cylinder_edge(Vector3<double> d, Vector3<double> hr)
45 {
46 double f(0), ze(fabs(d[2])-hr[2]);
47
48 d[2] = 0;
49
50 double ld(d.length());
51
52 if ( ld < 1 ) return ze;
53
54 Vector3<double> de(d/hr);
55 double lde(de.length());
56
57 if ( lde > 1e-20 )
58 f = ld*(1.0 - 1.0/lde);
59
60 if ( f < ze ) f = ze;
61
62 return f;
63 }
64
65 double shell_edge(Vector3<double> d, double mind, double maxd)
66 {
67 double f(0);
68
69 double ld(d.length());
70
71 mind = ld - mind ;
72 maxd -= ld;
73
74 if ( mind < maxd ) f = mind;
75 else f = maxd;
76
77 return f;
78 }
79
80
103 int Bimage::shape(int type, Vector3<long> rect, Vector3<double> start,
104 double width, int fill_type, double fill)
105 {
106 long nn;
107
108 for ( nn=0; nn<n; nn++ )
109 shape(nn, type, rect, start, width, fill_type, fill);
110
111 return 0;
112 }
113
137 int Bimage::shape(long nn, int type, Vector3<long> rect, Vector3<double> start,
138 double width, int fill_type, double fill)
139 {
140 if ( fabs(width) < 0.001 ) {
141 if ( width < 0 ) width = -0.001;
142 else width = 0.001;
143 }
144
145 if ( fill_type == FILL_AVERAGE ) fill = avg;
146 if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
147
148 if ( rect[0] < 1 ) rect[0] = x;
149 if ( rect[1] < 1 ) rect[1] = y;
150 if ( rect[2] < 1 ) rect[2] = z;
151 if ( z < 2 ) {
152 start[2] = 0;
153 rect[2] = z;
154 }
155
156 long i, xx, yy, zz, cc;
157 double f(0), edge(3*width), a(-GOLDEN/width);
158 Vector3<double> d, hr(rect/2);
159 Vector3<double> cx(start[0] + (rect[0] - 1)/2.0, start[1] + (rect[1] - 1)/2.0, start[2] + (rect[2] - 1)/2.0);
160 Vector3<long> lo(start - edge);
161 Vector3<long> hi(start + rect + edge);
162
163 hr = hr.max(1);
164 lo = lo.max(0);
165 if ( hi[0] >= x ) hi[0] = x - 1;
166 if ( hi[1] >= y ) hi[1] = y - 1;
167 if ( hi[2] >= z ) hi[2] = z - 1;
168
169 // cout << hr << endl;
170
171 if ( verbose & VERB_PROCESS ) {
172 cout << "Filling a shape:" << endl;
173 cout << "Shape: " << type << endl;
174 cout << "Start: " << setprecision(3) << start << endl;
175 cout << "Size: " << rect << endl;
176 cout << "Width and fill value: " << width << " " << fill << endl << endl;
177 }
178
179
180 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
181 d[2] = zz - cx[2];
182 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
183 d[1] = yy - cx[1];
184 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
185 d[0] = xx - cx[0];
186 if ( type == 0 )
187 f = rectangle_edge(d, hr);
188 else if ( type == 1 )
189 f = oval_edge(d, hr);
190 else if ( type == 2 )
191 f = cylinder_edge(d, hr);
192 f *= a;
193 if ( f > 50 ) edge = 1e30;
194 else edge = exp(f);
195 if ( !isfinite(edge) ) {
196 cerr << xx << " " << yy << " " << zz << ": Value too large or not finite!: " << edge << endl;
197 edge = 1e30;
198 }
199 i = index(xx, yy, zz, nn);
200 for ( cc=0; cc<c; cc++, i++ )
201 set(i, ((*this)[i] + fill*edge)/(1+edge));
202 }
203 }
204 }
205
206 statistics();
207
208 return 0;
209 }
210
231 Bimage* Bimage::edge_mask(int type, Vector3<long> rect,
232 Vector3<double> start, double width)
233 {
234 if ( fabs(width) < 0.001 ) {
235 if ( width < 0 ) width = -0.001;
236 else width = 0.001;
237 }
238
239 if ( rect[0] < 1 ) rect[0] = x;
240 if ( rect[1] < 1 ) rect[1] = y;
241 if ( rect[2] < 1 ) rect[2] = z;
242 if ( z < 2 ) {
243 start[2] = 0;
244 rect[2] = z;
245 }
246
247 long i, xx, yy, zz, cc;
248 Vector3<double> d, hr(rect/2);
249 Vector3<double> cx(start[0] + (rect[0] - 1)/2.0, start[1] + (rect[1] - 1)/2.0, start[2] + (rect[2] - 1)/2.0);
250 double f(0), edge, a(GOLDEN/width);
251
252 hr = hr.max(1);
253
254 // cout << hr << endl;
255
256 if ( verbose & VERB_PROCESS ) {
257 cout << "Creating an edge mask:" << endl;
258 cout << "Shape: " << type << endl;
259 cout << "Start: " << setprecision(3) << start << endl;
260 cout << "Size: " << rect << endl;
261 cout << "Width: " << width << endl << endl;
262 }
263
264 Bimage* pmask = new Bimage(Float, TSimple, size(), 1);
265
266 for ( i=0, zz=0; zz<z; zz++ ) {
267 d[2] = (double)zz - cx[2];
268 for ( yy=0; yy<y; yy++ ) {
269 d[1] = (double)yy - cx[1];
270 for ( xx=0; xx<x; xx++ ) {
271 d[0] = (double)xx - cx[0];
272 if ( type == 0 )
273 f = rectangle_edge(d, hr);
274 else if ( type == 1 )
275 f = oval_edge(d, hr);
276 else if ( type == 2 )
277 f = cylinder_edge(d, hr);
278 f *= a;
279 if ( f > 50 ) edge = 1e30;
280 else edge = exp(f);
281 if ( !isfinite(edge) ) {
282 cerr << xx << " " << yy << " " << zz << ": Value too large or not finite!: " << edge << endl;
283 edge = 1e30;
284 }
285 for ( cc=0; cc<c; cc++, i++ )
286 pmask->set(i, 1/(1+edge));
287 }
288 }
289 }
290
291 pmask->statistics();
292
293 return pmask;
294 }
295
319 int Bimage::edge(int type, Vector3<long> rect, Vector3<double> start,
320 double width, int fill_type, double fill)
321 {
322 Bimage* pmask = edge_mask(type, rect, start, width);
323
324 #ifdef HAVE_GCD
325 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(size_t nn){
326 apply_soft_mask(nn, pmask, fill_type, fill);
327 });
328 #else
329 #pragma omp parallel for
330 for ( long nn=0; nn<n; nn++ )
331 apply_soft_mask(nn, pmask, fill_type, fill);
332 #endif
333
334 delete pmask;
335
336 statistics();
337
338 return 0;
339 }
340
365 int Bimage::edge(long nn, int type, Vector3<long> rect, Vector3<double> start,
366 double width, int fill_type, double fill)
367 {
368 Bimage* pmask = edge_mask(type, rect, start, width);
369
370 apply_soft_mask(nn, pmask, fill_type, fill);
371
372 return 0;
373 }
374
386 int Bimage::hanning_taper(double fill)
387 {
388
389 long i, nn, xx, yy, zz, cc;
390 double vol, v;
391 Vector3<double> cx, han;
392
393 cx[0] = M_PI * 2.0L / ( x - 1);
394 cx[1] = M_PI * 2.0L / ( y - 1);
395 cx[2] = M_PI * 2.0L / ( z - 1);
396
397 if ( verbose & VERB_FULL ) {
398 cout << "Hann tapering window:" << endl;
399 cout << "Size: " << size() << endl;
400 cout << "Fill value: " << fill << endl << endl;
401 }
402
403 for ( i=nn=0; nn<n; nn++ ) {
404 for ( zz=0; zz<z; zz++ ) {
405 han[2] = 0.5 * (1. - cos(cx[2]*zz));
406 for ( yy=0; yy<y; yy++ ) {
407 han[1] = 0.5 * (1. - cos(cx[1]*yy));
408 for ( xx=0; xx<x; xx++ ) {
409 han[0] = 0.5 * (1. - cos(cx[0]*xx));
410 vol = han.volume();
411 for ( cc=0; cc<c; cc++, i++ ) {
412 v = ((*this)[i] - fill)*vol + fill;
413 set(i, v);
414 }
415 }
416 }
417 }
418 }
419
420 return 0;
421 }
422
438 int Bimage::sphere(Vector3<double> center, double radius,
439 double width, int fill_type, double fill)
440 {
441 Vector3<long> rect((long) (2*radius+0.5), (long) (2*radius+0.5), (long) (2*radius+0.5));
442 rect = rect.min(size());
443
444 center -= rect/2;
445
446 return shape(1, rect, center, width, fill_type, fill);
447 }
448
465 int Bimage::cylinder(Vector3<double> center, double radius,
466 double height, double width, int fill_type, double fill)
467 {
468 Vector3<long> cyl(long(2*radius+0.5), long(2*radius+0.5), long(height+0.5));
469 cyl = cyl.min(size());
470
471 center[0] -= radius;
472 center[1] -= radius;
473 center[2] -= height/2;
474
475 return shape(2, cyl, center, width, fill_type, fill);
476 }
477
492 int Bimage::gaussian_sphere(long nn, Vector3<double> center, double sigma, double amp)
493 {
494 if ( sigma < 1 ) sigma = 1;
495 if ( amp == 0 ) amp = 1;
496
497 if ( verbose ) {
498 cout << "Calculating a Gaussian sphere:" << endl;
499 cout << "Center: " << center << endl;
500 cout << "Sigma: " << sigma << endl;
501 cout << "Amplitude: " << amp << endl << endl;
502 }
503
504 long i, xx, yy, zz, cc;
505 double x2, y2, z2, d2, v;
506 double fac(-0.5/(sigma*sigma));
507
508 for ( i=zz=0; zz<z; zz++ ) {
509 z2 = zz - center[2];
510 z2 *= z2;
511 for ( yy=0; yy<y; yy++ ) {
512 y2 = yy - center[1];
513 y2 *= y2;
514 for ( xx=0; xx<x; xx++ ) {
515 x2 = xx - center[0];
516 x2 *= x2;
517 d2 = x2 + y2 + z2;
518 v = amp*exp(fac*d2);
519 for ( cc=0; cc<c; cc++, i++ )
520 add(i, v);
521 }
522 }
523 }
524
525 return 0;
526 }
527
544 int Bimage::shell(Vector3<double> center, double minrad,
545 double maxrad, double width, int fill_type, double fill)
546 {
547 long nn;
548
549 for ( nn=0; nn<n; nn++ )
550 shell(nn, center, minrad, maxrad, width, fill_type, fill);
551
552 return 0;
553 }
554
572 int Bimage::shell(long nn, Vector3<double> center, double minrad,
573 double maxrad, double width, int fill_type, double fill)
574 {
575 if ( minrad > maxrad ) swap(minrad, maxrad);
576 if ( maxrad - minrad < 1 ) return 0;
577
578 if ( fabs(width) < 0.1 ) {
579 if ( width < 0 ) width = -0.1;
580 else width = 0.1;
581 }
582
583 if ( fill_type == FILL_AVERAGE ) fill = avg;
584 if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
585
586 long i, xx, yy, zz, cc;
587 double f, edge, pad(5*width), mrp(maxrad + pad), a(GOLDEN/fabs(width));
588 Vector3<long> lo(center - mrp);
589 Vector3<long> hi(center + mrp);
590 Vector3<double> d;
591
592 if ( verbose & VERB_PROCESS ) {
593 cout << "Filling shell:" << endl;
594 cout << "Center: " << center << endl;
595 cout << "Radii: " << minrad << " - " << maxrad << endl;
596 cout << "Gaussian width and fill value: " << width << " " << fill << endl << endl;
597 }
598
599 // lo = center - (maxrad + pad);
600 lo = lo.max(0);
601 // hi = center + (maxrad + pad);
602 if ( hi[0] >= x ) hi[0] = x - 1;
603 if ( hi[1] >= y ) hi[1] = y - 1;
604 if ( hi[2] >= z ) hi[2] = z - 1;
605 /*
606 cout << lo << tab << hi << endl;
607
608 for ( xx=-2*maxrad; xx<2*maxrad; xx++ ) {
609 d[0] = xx;
610 f = shell_edge(d, minrad, maxrad);
611 f *= a;
612 if ( f > 40 ) edge = 1e30;
613 else edge = exp(f);
614 cout << xx << tab << f << tab << edge << endl;
615 }
616 */
617 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
618 d[2] = zz - center[2];
619 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
620 d[1] = yy - center[1];
621 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
622 d[0] = xx - center[0];
623 f = shell_edge(d, minrad, maxrad);
624 f *= a;
625 if ( f > 40 ) edge = 1e30;
626 else edge = exp(f);
627 i = index(0, xx, yy, zz, nn);
628 for ( cc=0; cc<c; cc++, i++ )
629 set(i, ((*this)[i] + fill*edge)/(1+edge));
630 }
631 }
632 }
633
634 return 0;
635 }
636
654 int Bimage::shell_wrap(long nn, Vector3<double> center, double minrad,
655 double maxrad, double width, int fill_type, double fill)
656 {
657 if ( minrad > maxrad ) swap(minrad, maxrad);
658 if ( maxrad - minrad < 1 ) return 0;
659
660 if ( fabs(width) < 0.1 ) {
661 if ( width < 0 ) width = -0.1;
662 else width = 0.1;
663 }
664
665 if ( fill_type == FILL_AVERAGE ) fill = avg;
666 if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
667
668 long i, xx, yy, zz, cc;
669 long ix, iy, iz;
670 double f, edge, mrw(maxrad + 3*width), a(GOLDEN/fabs(width));
671 Vector3<long> sh(size()/2);
672 Vector3<long> lo(center - mrw);
673 Vector3<long> hi(center + mrw);
674 Vector3<double> d;
675
676 if ( verbose & VERB_PROCESS ) {
677 cout << "Filling shell with wrapping:" << endl;
678 cout << "Center: " << center << endl;
679 cout << "Radii: " << minrad << " - " << maxrad << endl;
680 cout << "Gaussian width and fill value: " << width << " " << fill << endl << endl;
681 }
682
683 // lo = center - (maxrad + 3*width);
684 // hi = center + (maxrad + 3*width);
685
686 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
687 d[2] = zz - center[2];
688 if ( d[2] > sh[2] ) d[2] -= z;
689 if ( d[2] < -sh[2] ) d[2] += z;
690 iz = (zz<0)? zz + z: zz;
691 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
692 d[1] = yy - center[1];
693 if ( d[1] > sh[1] ) d[1] -= y;
694 if ( d[1] < -sh[1] ) d[1] += y;
695 iy = (yy<0)? yy + y: yy;
696 for ( xx=lo[0]; xx<=hi[0]; xx++ ) {
697 d[0] = xx - center[0];
698 if ( d[0] > sh[0] ) d[0] -= x;
699 if ( d[0] < -sh[0] ) d[0] += x;
700 ix = (xx<0)? xx + x: xx;
701 f = shell_edge(d, minrad, maxrad);
702 f *= a;
703 if ( f > 50 ) edge = 1e30;
704 else edge = exp(f);
705 i = index(ix, iy, iz, nn);
706 for ( cc=0; cc<c; cc++, i++ )
707 set(i, ((*this)[i] + fill*edge)/(1+edge));
708 }
709 }
710 }
711
712 return 0;
713 }
714
729 int Bimage::bar(Vector3<double> start, Vector3<double> end,
730 double width, double edge_width, int fill_type, double fill)
731 {
732 long nn;
733
734 for ( nn=0; nn<n; nn++ )
735 bar(nn, start, end, width, edge_width, fill_type, fill);
736
737 return 0;
738 }
739
755 int Bimage::bar(long nn, Vector3<double> start, Vector3<double> end,
756 double width, double edge_width, int fill_type, double fill)
757 {
758 if ( edge_width < 0.001 ) edge_width = 0.001;
759
760 if ( fill_type == FILL_AVERAGE ) fill = avg;
761 if ( fill_type == FILL_BACKGROUND ) fill = background(nn);
762
763 if ( verbose & VERB_PROCESS ) {
764 cout << "Generating a bar" << endl;
765 cout << "Start: " << start << endl;
766 cout << "End: " << end << endl;
767 cout << "Fill value: " << fill << endl;
768 cout << "Width and edge width: " << width << " " << edge_width << endl << endl;
769 }
770
771 long i, xx, yy, zz, cc;
772 double t, d, half_width(width/2.0), edge;
773 double a(GOLDEN/fabs(edge_width));
774
775 Vector3<double> vec(end - start);
776 Vector3<double> u, w;
777 double vlen(vec.length());
778 double vpow(vlen*vlen);
779 Vector3<double> lo, hi;
780
781 lo = start.min(end);
782 lo -= 3*edge_width;
783 lo = lo.max(0);
784 hi = start.max(end);
785 hi += 3*edge_width;
786 if ( hi[0] >= x ) hi[0] = x - 1;
787 if ( hi[1] >= y ) hi[1] = y - 1;
788 if ( hi[2] >= z ) hi[2] = z - 1;
789
790 for ( zz=lo[2]; zz<=hi[2]; zz++ ) {
791 u[2] = zz;
792 for ( yy=lo[1]; yy<=hi[1]; yy++ ) {
793 u[1] = yy;
794 for ( xx=lo[0]; xx<=hi[0]; xx++, i++ ) {
795 u[0] = xx;
796 w = start - u;
797 t = -w.scalar(vec)/vpow;
798 if ( t >= 0 && t <= 1 ) {
799 d = (vec.cross(w)).length()/vlen;
800 edge = exp(a*(half_width - d));
801 if ( !isfinite(edge) || edge > 1e30 ) edge = 1e30;
802 i = index(xx, yy, zz, nn);
803 for ( cc=0; cc<c; cc++, i++ )
804 set(i, ((*this)[i] + fill*edge)/(1+edge));
805 }
806 }
807 }
808 }
809
810 return 0;
811 }
812
819 int Bimage::quadric(double* param)
820 {
821 long i, xx, yy, zz, nn;
822 double dx, dy, dz, v;
823
824 for ( i=nn=0; nn<n; nn++ ) {
825 for ( zz=0; zz<z; zz++ ) {
826 dz = -image[nn].origin()[2] + zz;
827 for ( yy=0; yy<y; yy++ ) {
828 dy = -image[nn].origin()[1] + yy;
829 for ( xx=0; xx<x; xx++, i++ ) {
830 dx = -image[nn].origin()[0] + xx;
831 v = param[0] + dx*param[1] + dy*param[2] + dz*param[3]
832 + dx*dx*param[4] + dy*dy*param[5] + dz*dz*param[6];
833 set(i, v);
834 }
835 }
836 }
837 }
838
839 return 0;
840 }
841
842
853 int Bimage::fill_gaps(long step)
854 {
855 if ( compoundtype != TSimple ) {
856 cerr << "Error: The gap filter only operates on single value images!" << endl << endl;
857 return -1;
858 }
859
860 long kernel_size(step);
861 double fill(200), v;
862 if ( kernel_size%2 == 0 ) kernel_size += 1;
863 if ( kernel_size < 3 ) kernel_size = 3;
864
865 // Calculate the new size and set up
866 long i, j, nn, xx, yy, zz, kx, ky, kz;
867 Vector3<long> blocksize(kernel_size,kernel_size,kernel_size);
868 blocksize = blocksize.min(size());
869 long blocktotalsize(blocksize.volume());
870
871 if ( verbose & VERB_PROCESS ) {
872 cout << "Filling the gaps:" << endl;
873 cout << "Block size: " << blocksize[0] << " x "
874 << blocksize[1] << " x " << blocksize[2] << " = " << blocktotalsize << endl;
875 }
876
877 change_type(Float);
878
879 // Do the fill filtering
880 long zlo, zhi, ylo, yhi, xlo, xhi;
881 for ( nn=0; nn<n; nn++ ) {
882 for ( zz=0; zz<z; zz+=step ) {
883 zlo = zz - blocksize[2]/2;
884 if ( zlo < 0 ) zlo = 0;
885 zhi = zz + blocksize[2]/2;
886 if ( zhi >= z ) zhi = z - 1;
887 for ( yy=0; yy<y; yy+=step ) {
888 ylo = yy - blocksize[1]/2;
889 if ( ylo < 0 ) ylo = 0;
890 yhi = yy + blocksize[1]/2;
891 if ( yhi >= y ) yhi = y - 1;
892 for ( xx=0; xx<x; xx+=step ) {
893 xlo = xx - blocksize[0]/2;
894 if ( xlo < 0 ) xlo = 0;
895 xhi = xx + blocksize[0]/2;
896 if ( xhi >= x ) xhi = x - 1;
897 i = index(0, xx, yy, zz, nn);
898 v = (*this)[i];
899 if ( v < fill ) {
900 for ( kz=zlo; kz<=zhi; kz++ ) {
901 for ( ky=ylo; ky<=yhi; ky++ ) {
902 for ( kx=xlo; kx<=xhi; kx++ ) {
903 j = index(0, kx, ky, kz, nn);
904 set(j, v);
905 }
906 }
907 }
908 }
909 }
910 }
911 }
912 }
913
914 if ( verbose & VERB_DEBUG )
915 cout << "DEBUG Bimage::fill_gaps: Done" << endl;
916
917 statistics();
918
919 return 0;
920 }
921
931 int Bimage::interpolate_gaps(long step)
932 {
933 if ( compoundtype != TSimple ) {
934 cerr << "Error: The gap filter only operates on single value images!" << endl << endl;
935 return -1;
936 }
937
938 // Calculate the new size and set up
939 long i, nn, xx, yy, zz;
940 long x1(0), x2(0), y1(0), y2(0), z1(0), z2(0);
941 double fx, fx1, fy, fy1, fz, fz1, v[8], vn;
942 for ( i=0; i<8; ++i ) v[i] = 0;
943
944 if ( verbose & VERB_PROCESS ) {
945 cout << "Interpolating the gaps:" << endl;
946 cout << "Step size: " << step << endl;
947 }
948
949 change_type(Float);
950
951 // Do the fill filtering
952 for ( i=nn=0; nn<n; nn++ ) {
953 for ( zz=0; zz<z; zz++ ) {
954 if ( zz%step == 0 ) {
955 z1 = zz;
956 z2 = z1 + step;
957 }
958 fz = (zz - z1)*1.0/step;
959 fz1 = 1 - fz;
960 for ( yy=0; yy<y; yy++ ) {
961 if ( yy%step == 0 ) {
962 y1 = yy;
963 y2 = y1 + step;
964 }
965 fy = (yy - y1)*1.0/step;
966 fy1 = 1 - fy;
967 for ( xx=0; xx<x; xx++, i++ ) {
968 if ( xx%step == 0 ) {
969 x1 = xx;
970 x2 = x1 + step;
971 v[0] = get(nn, x1, y1, z1);
972 v[1] = get(nn, x2, y1, z1);
973 v[2] = get(nn, x1, y2, z1);
974 v[3] = get(nn, x2, y2, z1);
975 v[4] = get(nn, x1, y1, z2);
976 v[5] = get(nn, x2, y1, z2);
977 v[6] = get(nn, x1, y2, z2);
978 v[7] = get(nn, x2, y2, z2);
979 }
980 fx = (xx - x1)*1.0/step;
981 fx1 = 1 - fx;
982 vn = fx1 * fy1 * fz1 * v[0];
983 vn += fx * fy1 * fz1 * v[1];
984 vn += fx1 * fy * fz1 * v[2];
985 vn += fx * fy * fz1 * v[3];
986 vn += fx1 * fy1 * fz * v[4];
987 vn += fx * fy1 * fz * v[5];
988 vn += fx1 * fy * fz * v[6];
989 vn += fx * fy * fz * v[7];
990 set(i, vn);
991 }
992 }
993 }
994 }
995
996 if ( verbose & VERB_DEBUG )
997 cout << "DEBUG Bimage::interpolate_gaps: Done" << endl;
998
999 statistics();
1000
1001 return 0;
1002 }
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bimage::shell_wrap
int shell_wrap(long nn, Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value with wrapping.
Definition: Bimage_edit.cpp:654
Vector3::cross
Vector3 cross(const Vector3 &v)
Definition: Vector3.h:250
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
Bimage.h
Header file for image class.
Vector3::length
double length()
Definition: Vector3.h:222
Bimage::add
void add(long j, double v)
Definition: Bimage.h:308
utilities.h
Header file for general utilities.
Vector3::abs
Vector3 abs()
Definition: Vector3.h:201
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Bimage::bar
int bar(Vector3< double > start, Vector3< double > end, double width, double edge_width, int fill_type=0, double fill=0)
Generates a bar between start and end points.
Definition: Bimage_edit.cpp:729
Bimage::shape
int shape(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Creates a shape in an image and fills it with a constant value.
Definition: Bimage_edit.cpp:103
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:319
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:383
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
GOLDEN
#define GOLDEN
Definition: utilities.h:81
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bimage::Bimage
Bimage()
Initializes an image.
Definition: Bimage.cpp:44
TSimple
Definition: Bimage.h:58
Float
Definition: utilities.h:157
Bimage::cylinder
int cylinder(Vector3< double > center, double radius, double height, double width, int fill_type=0, double fill=0)
Fills a cylinder within an image with a uniform value.
Definition: Bimage_edit.cpp:465
Vector3::max
Type max()
Definition: Vector3.h:175
Bimage
General image parameter class.
Definition: Bimage.h:163
M_PI
#define M_PI
Definition: utilities.h:59
oval_edge
double oval_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:27
isfinite
bool isfinite(complex< T > &value)
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:247
Bimage::apply_soft_mask
long apply_soft_mask(long nn, Bimage *pmask, int fill_type, double fill)
Applies a soft mask to a sub-image.
Definition: Bimage_mask.cpp:2330
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bimage::sphere
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:438
length
double length(vector< T > v)
Definition: Vector3.h:528
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bimage::interpolate_gaps
int interpolate_gaps(long step)
Interpolate the voxels that are not calculated.
Definition: Bimage_edit.cpp:931
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bimage::hanning_taper
int hanning_taper(double fill=0)
Apply Hanning taper window to the image.
Definition: Bimage_edit.cpp:386
Bimage::get
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
Definition: Bimage.cpp:937
Bimage::fill_gaps
int fill_gaps(long step)
Fill the voxels that are not calculated.
Definition: Bimage_edit.cpp:853
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
Bimage::quadric
int quadric(double *param)
Generates a quadric surface over the whole image.
Definition: Bimage_edit.cpp:819
shell_edge
double shell_edge(Vector3< double > d, double mind, double maxd)
Definition: Bimage_edit.cpp:65
Bimage::shell
int shell(Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value.
Definition: Bimage_edit.cpp:544
Bimage::pad
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Definition: Bimage_resize.cpp:351
matrix_linear.h
Header file for matrix functions.
cylinder_edge
double cylinder_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:44
verbose
int verbose
Bimage::edge_mask
Bimage * edge_mask(int type, Vector3< long > rect, Vector3< double > start, double width)
Creates a mask with the edge approaching zero.
Definition: Bimage_edit.cpp:231
Vector3< double >
Vector3::min
Type min()
Definition: Vector3.h:169
Bimage::center
int center(int fill_type=0, double fill=0)
Centers an image.
Definition: Bimage_transform.cpp:699
Bimage::gaussian_sphere
int gaussian_sphere(long nn, Vector3< double > center, double sigma, double amp)
Fills a gaussian sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:492
Bimage::fill
void fill(double v)
Definition: Bimage.h:698
Bimage::height
Bimage * height(View *views, double threshold=0)
Calculates a set of height images from a 3D density map.
Definition: Bimage_topo.cpp:230
Vector3::volume
double volume()
Definition: Vector3.h:235
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
Bimage::background
double background(long nn)
Definition: Bimage.h:542
rectangle_edge
double rectangle_edge(Vector3< double > d, Vector3< double > hr)
Definition: Bimage_edit.cpp:17
Bimage::image
Bsub_image * image
Definition: Bimage.h:188