| 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_montage.cpp
Go to the documentation of this file.
1
9 #include "img_montage.h"
10 #include "datatypes.h"
11
12 // Declaration of global variables
13 extern int verbose; // Level of output to the screen
14
29 Bimage* img_montage_slices(Bimage* p, int first, int cols, int rows, int skip, int flipy)
30 {
31 if ( p->sizeZ() < 2 ) return NULL;
32
33 if ( first < 0 ) first = 0;
34 if ( first > p->sizeZ() ) first = p->sizeZ() - 1;
35
36 unsigned long incr = 1;
37 if ( skip > 0 ) incr = skip + 1;
38
39 unsigned long i, j, x, y, c, z, z1, ix, iy, nx, ny;
40
41 if ( cols < 1 ) {
42 cols = (int) (sqrt((1.0*p->sizeZ() - first)/incr) + 0.99);
43 if ( cols*p->sizeX() > 1500 ) cols = 1500/p->sizeX();
44 if ( cols < 1 ) cols = 1;
45 if ( cols > (p->sizeZ() - first)/incr ) cols = (p->sizeZ() - first)/incr;
46 }
47 if ( rows < 1 )
48 rows = ((p->sizeZ() - first)/incr - 1)/cols + 1;
49
50 if ( verbose & VERB_LABEL )
51 cout << "Creating a montage of " << cols << " x " << rows << " slices" << endl << endl;
52
53 Bimage* pm = new Bimage(p->data_type(), p->compound_type(), cols*p->sizeX(), rows*p->sizeY(), 1, 1);
54 pm->fill(p->image->background());
55
56 for ( z=first, z1=cols*rows*incr + first; z<z1 && z<p->sizeZ(); z+=incr ) {
57 ny = ((z - first)/incr)/cols;
58 if ( flipy ) ny = rows - ny - 1;
59 nx = (z - first)/incr - ny*cols;
60 for ( y=0; y<p->sizeY(); y++ ) {
61 iy = y + p->sizeY()*ny;
62 for ( x=0; x<p->sizeX(); x++ ) {
63 ix = x + p->sizeX()*nx;
64 i = (iy*cols*p->sizeX() + ix)*p->channels();
65 j = ((z*p->sizeY() + y)*p->sizeX() + x)*p->channels();
66 for ( c=0; c<p->channels(); c++, i++, j++ ) pm->set(i, (*p)[j]);
67 }
68 }
69 }
70
71 pm->statistics();
72
73 return pm;
74 }
75
90 Bimage* img_montage_images(Bimage* p, int first, int cols, int rows, int skip, int flipy)
91 {
92 if ( p->sizeZ() > 1 || p->images() < 2 ) return NULL;
93
94 if ( first < 0 ) first = 0;
95 if ( first > p->images() ) first = p->images() - 1;
96
97 unsigned long incr = 1;
98 if ( skip > 0 ) incr = skip + 1;
99
100 unsigned long i, j, x, y, c, n, n1, ix, iy, nx, ny;
101
102 if ( cols < 1 ) {
103 cols = (int) (sqrt((1.0*p->images() - first)/incr) + 0.99);
104 if ( cols*p->sizeX() > 1500 ) cols = 1500/p->sizeX();
105 if ( cols < 1 ) cols = 1;
106 if ( cols > (p->images() - first)/incr ) cols = (p->images() - first)/incr;
107 }
108 if ( rows < 1 )
109 rows = ((p->images() - first)/incr - 1)/cols + 1;
110
111 if ( verbose & VERB_LABEL )
112 cout << "Creating a montage of " << cols << " x " << rows << " images" << endl << endl;
113
114 Bimage* pm = new Bimage(p->data_type(), p->compound_type(), cols*p->sizeX(), rows*p->sizeY(), 1, 1);
115 pm->fill(p->image->background());
116
117 for ( n=first, n1=cols*rows*incr + first; n<n1 && n<p->images(); n+=incr ) {
118 ny = ((n - first)/incr)/cols;
119 if ( flipy ) ny = rows - ny - 1;
120 nx = (n - first)/incr - ny*cols;
121 for ( y=0; y<p->sizeY(); y++ ) {
122 iy = y + p->sizeY()*ny;
123 for ( x=0; x<p->sizeX(); x++ ) {
124 ix = x + p->sizeX()*nx;
125 i = (iy*cols*p->sizeX() + ix)*p->channels();
126 j = ((n*p->sizeY() + y)*p->sizeX() + x)*p->channels();
127 for ( c=0; c<p->channels(); c++, i++, j++ ) pm->set(i, (*p)[j]);
128 }
129 }
130 }
131
132 pm->statistics();
133
134 return pm;
135 }
Bimage::images
unsigned long images()
Definition: Bimage.h:403
Bimage::sizeX
void sizeX(unsigned long nx)
Definition: Bimage.h:333
Bsub_image::background
double background()
Definition: Bimage.h:123
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:293
datatypes.h
Functions to check and convert datatypes.
Bimage::statistics
size_t statistics()
Calculates the statistics for an image.
Definition: Bimage.cpp:2422
img_montage_images
Bimage * img_montage_images(Bimage *p, int first, int cols, int rows, int skip, int flipy)
Rearranges a 2D images into a 2D montage.
Definition: img_montage.cpp:90
Bimage::channels
unsigned long channels()
Definition: Bimage.h:328
Bimage
General image parameter class.
Definition: Bimage.h:149
img_montage.h
Functions to montage images for display.
Bimage::set
void set(unsigned long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:904
verbose
int verbose
img_montage_slices
Bimage * img_montage_slices(Bimage *p, int first, int cols, int rows, int skip, int flipy)
Rearranges a 3D image into a montage of 2D slices for display.
Definition: img_montage.cpp:29
Bimage::sizeZ
void sizeZ(unsigned long nz)
Definition: Bimage.h:335
Bimage::sizeY
void sizeY(unsigned long ny)
Definition: Bimage.h:334
Bimage::fill
void fill(double v)
Definition: Bimage.h:489
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:98
Bimage::data_type
DataType data_type()
Definition: Bimage.h:291
Bimage::image
Bsub_image * image
Definition: Bimage.h:180