| Bsoft 2.0.5 Bernard's software package

Bimage_montage.cpp
Go to the documentation of this file.
1
9 #include "Bimage.h"
10
11 // Declaration of global variables
12 extern int verbose; // Level of output to the screen
13
14 int Bimage::montage_one(Bimage* pm, long zz, long mi, long cols, long rows, int flip)
15 {
16 long i, j, xx, yy, ix, iy, cc;
17 long ny = mi/cols;
18 long nx = mi - ny*cols;
19
20 if ( flip & 1 ) nx = cols - nx - 1;
21 if ( flip & 2 ) ny = rows - ny - 1;
22
23 nx *= x;
24 ny *= y;
25
26 for ( j=zz*y*x*c, yy=0, iy=ny*pm->x; yy<y; yy++, iy+=pm->x ) {
27 for ( xx=0, ix=nx; xx<x; xx++, ix++ ) {
28 i = (iy + ix)*c;
29 for ( cc=0; cc<c; cc++, i++, j++ ) pm->set(i, (*this)[j]);
30 }
31 }
32
33 return 0;
34 }
35
49 Bimage* Bimage::montage(int first, int cols, int rows, int skip, int flip)
50 {
51 if ( first < 0 ) first = 0;
52 if ( first > n*z ) first = n*z - 1;
53
54 long incr(1);
55 if ( skip > 0 ) incr = skip + 1;
56
57 if ( cols < 1 ) {
58 cols = (int) (sqrt((1.0*n*z - first)/incr) + 0.99);
59 if ( cols*x > 1500 ) cols = 1500/x;
60 if ( cols < 1 ) cols = 1;
61 if ( cols > (n*z - first)/incr ) cols = (n*z - first)/incr;
62 }
63 if ( rows < 1 )
64 rows = ((n*z - first)/incr - 1)/cols + 1;
65
66 if ( verbose & VERB_LABEL )
67 cout << "Creating a montage of " << cols << " x " << rows << " slices" << endl << endl;
68
69 Bimage* pm = new Bimage(datatype, compoundtype, cols*x, rows*y, 1, 1);
70 pm->sampling(sampling());
71 pm->fill(background(long(0)));
72
73 #ifdef HAVE_GCD
74 dispatch_apply(cols*rows, dispatch_get_global_queue(0, 0), ^(size_t i){
75 long zz(first+i*incr);
76 if ( zz < n*z ) montage_one(pm, zz, i, cols, rows, flip);
77 });
78 #else
79 #pragma omp parallel for
80 for ( long i=0; i<cols*rows; i++ ) {
81 long zz(first+i*incr);
82 if ( zz < n*z ) montage_one(pm, zz, i, cols, rows, flip);
83 }
84 #endif
85
86 pm->statistics();
87
88 return pm;
89 }
90
Bimage.h
Header file for image class.
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bimage::montage
Bimage * montage(int first, int cols, int rows, int skip=0, int flipy=0)
Rearranges an image into a montage of 2D slices for display.
Definition: Bimage_montage.cpp:49
Bimage::Bimage
Bimage()
Initializes an image.
Definition: Bimage.cpp:44
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
verbose
int verbose
Bimage::fill
void fill(double v)
Definition: Bimage.h:698
Bimage::background
double background(long nn)
Definition: Bimage.h:542
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106