31 int wrap,
int fill_type,
float fill)
35 if ( newsize.
x() < 1 ) newsize[0] = p->
sizeX();
36 if ( newsize.
y() < 1 ) newsize[1] = p->
sizeY();
37 if ( newsize.
z() < 1 ) newsize[2] = p->
sizeZ();
39 unsigned long i, j, c, x, y, z, n;
40 long oldx, oldy, oldz;
47 if ( wrap ) cout <<
"Resizing with wrapping:" << endl;
48 else cout <<
"Resizing:" << endl;
49 cout <<
"Shift: " << translate << endl;
50 cout <<
"New size: " << newsize << endl;
52 cout <<
"Fill value: " << fill << endl;
55 cout <<
"Resizing" << endl << endl;
62 for ( i=n=0; n<p->
images(); n++ ) {
65 cout <<
"Image " << n+1 <<
" new origin: " << pnu->
image[n].
origin() << endl;
69 cout <<
"Image " << n+1 <<
" fill value: " << fill << endl;
71 for ( z=0; z<pnu->
sizeZ(); z++ ) {
72 oldz = (long)z - translate.
z();
74 while ( oldz < 0 ) oldz += p->
sizeZ();
75 while ( oldz >= p->
sizeZ() ) oldz -= p->
sizeZ();
77 for ( y=0; y<pnu->
sizeY(); y++ ) {
78 oldy = (long)y - translate.
y();
80 while ( oldy < 0 ) oldy += p->
sizeY();
81 while ( oldy >= p->
sizeY() ) oldy -= p->
sizeY();
83 for ( x=0; x<pnu->
sizeX(); x++ ) {
84 oldx = (long)x - translate.
x();
86 while ( oldx < 0 ) oldx += p->
sizeX();
87 while ( oldx >= p->
sizeX() ) oldx -= p->
sizeX();
89 if ( oldx < 0 || oldx >= p->
sizeX() || oldy < 0 ||
90 oldy >= p->
sizeY() || oldz < 0 || oldz >= p->
sizeZ() ) {
91 for ( c=0; c<p->
channels(); c++, i++ ) pnu->
set(i, fill);
94 j = p->
index(0, oldx, oldy, oldz, n);
95 for ( c=0; c<p->
channels(); c++, i++, j++ ) pnu->
set(i, (*p)[j]);
106 cerr <<
tab <<
"in img_resize" << endl;
132 if ( newsize.
x() == p->
sizeX() && newsize.
y() == p->
sizeY() && newsize.
z() == p->
sizeZ() )
137 return img_resize(p, newsize, translate, 0, fill_type, fill);
159 if ( translate.
x() == 0 && translate.
y() == 0 && translate.
z() == 0 &&
163 unsigned long i, j, c, x, y, z, n;
164 long newx, newy, newz;
167 cout <<
"Shrinking and wrapping:" << endl;
168 cout <<
"New size: " << newsize << endl;
169 cout <<
"New origin: " << translate << endl << endl;
171 cout <<
"Shrinking and wrapping" << endl << endl;
177 unsigned long nudatasize = newsize.
x()*newsize.
y()*newsize.
z()*p->
images()*p->
channels();
178 float* nudata =
new float[nudatasize];
179 for ( i=0; i<nudatasize; i++ ) nudata[i] = 0;
181 for ( i=n=0; n<p->
images(); n++ ) {
182 for ( z=0; z<p->
sizeZ(); z++ ) {
183 newz = z + translate.
z();
184 if ( newz < 0 ) newz += newsize.
z();
185 if ( newz >= newsize.
z() ) newz -= newsize.
z();
186 for ( y=0; y<p->
sizeY(); y++ ) {
187 newy = y + translate.
y();
188 if ( newy < 0 ) newy += newsize.
y();
189 if ( newy >= newsize.
y() ) newy -= newsize.
y();
190 for ( x=0; x<p->
sizeX(); x++ ) {
191 newx = x + translate.
x();
192 if ( newx < 0 ) newx += newsize.
x();
193 if ( newx >= newsize.
x() ) newx -= newsize.
x();
194 j = (((n*newsize.
z()+newz)*newsize.
y() + newy)*newsize.
x() + newx)*p->
channels();
195 for ( c=0; c<p->
channels(); c++, i++, j++ )
196 nudata[j] += (*p)[i];
208 cerr <<
tab <<
"in img_shrink_wrap" << endl;
231 if ( newsize[0] > 1 ) newsize[0] = size;
232 if ( newsize[1] > 1 ) newsize[1] = size;
233 if ( newsize[2] > 1 ) newsize[2] = size;
238 return img_resize(p, newsize, translate, wrap, fill_type, fill);
259 return img_resize(p, size, translate, wrap, fill_type, fill);
void change_type(char letter)
Get the data type indicated by a single letter code.
Bimage * img_pad(Bimage *p, int size, int fill_type, float fill)
Pads an image to a new size with a given fill value.
void sizeX(unsigned long nx)
Header file for general utilities.
int img_shrink_wrap(Bimage *p, Vector3< int > newsize, Vector3< int > translate)
Shrinks an image to a new size with wrapping of the excluded edges.
Bimage * img_resize_to_next_power2(Bimage *p, int fill_type, float fill)
Resizes without interpolation or rescaling to the next power of 2.
Generalized matrix class.
double average(unsigned long cc, double xf, double yf, double zf, unsigned long nn, double iscale)
Averages in the xy plane when scaling is less than 1.
size_t statistics()
Calculates the statistics for an image.
General image parameter class.
unsigned char * data_alloc()
unsigned long index(unsigned long nx, unsigned long ny)
void set(unsigned long j, double v)
Sets a single value at the given index.
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
DataType
Base data type specifier.
void origin(double x, double y, double z)
unsigned char * data_pointer()
void sizeZ(unsigned long nz)
Bimage * img_resize(Bimage *p, Vector3< int > newsize, Vector3< int > translate, int wrap, int fill_type, float fill)
Resizes without interpolation or rescaling.
Header file for 2D and 3D image I/O.
void sizeY(unsigned long ny)
Vector3< int > page_size()
int findNextPowerOf(int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
ostream & tab(ostream &out)