29 int fill_type,
double fill)
32 cout <<
"DEBUG Bimage::resize: " << nusize << endl;
34 if ( nusize ==
size() )
return 0;
36 if ( nusize[0] < 1 ) nusize[0] = x;
37 if ( nusize[1] < 1 ) nusize[1] = y;
38 if ( nusize[2] < 1 ) nusize[2] = z;
44 long i, j, xx, yy, zz, nn;
45 long oldx, oldy, oldz;
47 long nualloc = (long) nusize.
volume()*n*elementsize;
48 long fomsize = (long) nusize.
volume()*n*
sizeof(float);
49 unsigned char* nudata =
new unsigned char[nualloc];
54 nufom =
new float[fomsize];
55 for ( i=0; i<fomsize; i++ ) nufom[i] = 0;
59 cout <<
"Resizing:" << endl;
60 cout <<
"Shift: " << translate << endl;
61 cout <<
"New size: " << nusize << endl;
63 cout <<
"Fill value: " <<
fill << endl;
69 for ( i=nn=0; nn<n; nn++ ) {
79 for ( zz=0; zz<nusize[2]; zz++ ) {
80 oldz = (long)zz - translate[2];
81 for ( yy=0; yy<nusize[1]; yy++ ) {
82 oldy = (long)yy - translate[1];
83 for ( xx=0; xx<nusize[0]; xx++, i++ ) {
84 oldx = (long)xx - translate[0];
85 if ( oldx < 0 || oldx >= x || oldy < 0 ||
86 oldy >= y || oldz < 0 || oldz >= z ) {
87 memcpy(nudata+i*elementsize, fp.
uc, elementsize);
89 j =
index(oldx, oldy, oldz, nn);
90 memcpy(nudata+i*elementsize, d.
uc+j*elementsize, elementsize);
91 if ( fom ) nufom[i] = fom[j];
125 int fill_type,
double fill)
129 if ( nusize[0] < 1 ) nusize[0] = x;
130 if ( nusize[1] < 1 ) nusize[1] = y;
131 if ( nusize[2] < 1 ) nusize[2] = z;
133 long i, j, cc, xx, yy, zz, nn;
134 long oldx, oldy, oldz;
141 cout <<
"Resizing:" << endl;
142 cout <<
"Shift: " << translate << endl;
143 cout <<
"New size: " << nusize << endl;
145 cout <<
"Fill value: " <<
fill << endl;
148 cout <<
"Resizing" << endl << endl;
155 for ( i=nn=0; nn<n; nn++ ) {
159 cout <<
"Image " << nn+1 <<
" new origin: " << pnu->
image[nn].
origin() << endl;
163 cout <<
"Image " << nn+1 <<
" fill value: " <<
fill << endl;
165 for ( zz=0; zz<pnu->
sizeZ(); zz++ ) {
166 oldz = (long)zz - translate[2];
167 for ( yy=0; yy<pnu->
sizeY(); yy++ ) {
168 oldy = (long)yy - translate[1];
169 for ( xx=0; xx<pnu->
sizeX(); xx++ ) {
170 oldx = (long)xx - translate[0];
171 if ( oldx < 0 || oldx >= x || oldy < 0 ||
172 oldy >= y || oldz < 0 || oldz >= z ) {
173 for ( cc=0; cc<c; cc++, i++ ) pnu->
set(i,
fill);
175 j =
index(0, oldx, oldy, oldz, nn);
176 for ( cc=0; cc<c; cc++, i++, j++ ) pnu->
set(i, (*
this)[j]);
187 cerr <<
tab <<
"in Bimage::resize" << endl;
204 if ( nusize[0] < 1 ) nusize[0] = x;
205 if ( nusize[1] < 1 ) nusize[1] = y;
206 if ( nusize[2] < 1 ) nusize[2] = z;
208 long i, j, xx, yy, zz, nn;
209 long oldx, oldy, oldz;
211 long nualloc = (long) nusize.
volume()*n*elementsize;
212 long fomsize = (long) nusize.
volume()*n*
sizeof(float);
213 unsigned char* nudata =
new unsigned char[nualloc];
218 nufom =
new float[fomsize];
219 for ( i=0; i<fomsize; i++ ) nufom[i] = 0;
223 cout <<
"Resizing with wrapping:" << endl;
224 cout <<
"Shift: " << translate << endl;
225 cout <<
"New size: " << nusize << endl;
229 for ( i=nn=0; nn<n; nn++ ) {
234 for ( zz=0; zz<nusize[2]; zz++ ) {
235 oldz = (long)zz - translate[2];
236 while ( oldz < 0 ) oldz += z;
237 while ( oldz >= z ) oldz -= z;
238 for ( yy=0; yy<nusize[1]; yy++ ) {
239 oldy = (long)yy - translate[1];
240 while ( oldy < 0 ) oldy += y;
241 while ( oldy >= y ) oldy -= y;
242 for ( xx=0; xx<nusize[0]; xx++, i++ ) {
243 oldx = (long)xx - translate[0];
244 while ( oldx < 0 ) oldx += x;
245 while ( oldx >= x ) oldx -= x;
246 j =
index(oldx, oldy, oldz, nn);
247 memcpy(nudata+i*elementsize, d.
uc+j*elementsize, elementsize);
248 if ( fom ) nufom[i] = fom[j];
284 if ( nusize[0] < 1 ) nusize[0] = x;
285 if ( nusize[1] < 1 ) nusize[1] = y;
286 if ( nusize[2] < 1 ) nusize[2] = z;
288 long i, j, cc, xx, yy, zz, nn;
289 long oldx, oldy, oldz;
292 cout <<
"Resizing with wrapping:" << endl;
293 cout <<
"Shift: " << translate << endl;
294 cout <<
"New size: " << nusize << endl;
297 cout <<
"Resizing" << endl << endl;
304 for ( i=nn=0; nn<n; nn++ ) {
307 cout <<
"Image " << nn+1 <<
" new origin: " << pnu->
image[nn].
origin() << endl;
308 for ( zz=0; zz<pnu->
sizeZ(); zz++ ) {
309 oldz = (long)zz - translate[2];
310 while ( oldz < 0 ) oldz += z;
311 while ( oldz >= z ) oldz -= z;
312 for ( yy=0; yy<pnu->
sizeY(); yy++ ) {
313 oldy = (long)yy - translate[1];
314 while ( oldy < 0 ) oldy += y;
315 while ( oldy >= y ) oldy -= y;
316 for ( xx=0; xx<pnu->
sizeX(); xx++ ) {
317 oldx = (long)xx - translate[0];
318 while ( oldx < 0 ) oldx += x;
319 while ( oldx >= x ) oldx -= x;
320 j =
index(0, oldx, oldy, oldz, nn);
321 for ( cc=0; cc<c; cc++, i++, j++ ) pnu->
set(i, (*
this)[j]);
331 cerr <<
tab <<
"in Bimage::resize" << endl;
350 if ( x < 2 ) nusize[0] = 1;
351 if ( y < 2 ) nusize[1] = 1;
352 if ( z < 2 ) nusize[2] = 1;
356 return resize(nusize, translate, fill_type,
fill);
374 return resize(sz, translate, fill_type,
fill);
391 if ( x < 2 ) nusize[0] = 1;
392 if ( y < 2 ) nusize[1] = 1;
393 if ( z < 2 ) nusize[2] = 1;
436 if ( translate[0] == 0 && translate[1] == 0 && translate[2] == 0 &&
437 nusize[0] == x && nusize[1] == y && nusize[2] == z )
440 long i, j, cc, xx, yy, zz, nn;
444 cout <<
"Shrinking and wrapping:" << endl;
445 cout <<
"New size: " << nusize << endl;
446 cout <<
"New origin: " << translate << endl << endl;
448 cout <<
"Shrinking and wrapping" << endl << endl;
452 long nudatasize = nusize[0]*nusize[1]*nusize[2]*n*c;
453 float* nudata =
new float[nudatasize];
454 for ( i=0; i<nudatasize; i++ ) nudata[i] = 0;
456 for ( i=nn=0; nn<n; nn++ ) {
457 for ( zz=0; zz<z; zz++ ) {
458 nuz = zz + translate[2];
459 if ( nuz < 0 ) nuz += nusize[2];
460 if ( nuz >= nusize[2] ) nuz -= nusize[2];
461 for ( yy=0; yy<y; yy++ ) {
462 nuy = yy + translate[1];
463 if ( nuy < 0 ) nuy += nusize[1];
464 if ( nuy >= nusize[1] ) nuy -= nusize[1];
465 for ( xx=0; xx<x; xx++ ) {
466 nux = xx + translate[0];
467 if ( nux < 0 ) nux += nusize[0];
468 if ( nux >= nusize[0] ) nux -= nusize[0];
469 j = (((nn*nusize[2] + nuz)*nusize[1] + nuy)*nusize[0] + nux)*c;
470 for ( cc=0; cc<c; cc++, i++, j++ )
471 nudata[j] += (*
this)[i];
483 cerr <<
tab <<
"in Bimage::shrink_wrap" << endl;
505 long i, j, xx, yy, zz, nn;
506 long oldx, oldy, oldz;
510 cout <<
"Enlarging:" << endl;
511 cout <<
"Scale: " << scale << endl;
512 cout <<
"New size: " << nusize << endl << endl;
515 long nudatasize = nusize[0]*nusize[1]*nusize[2]*n*elementsize;
516 char* nudata =
new char[nudatasize];
518 for ( i=nn=0; nn<n; nn++ ) {
520 for ( zz=0; zz<nusize[2]; zz++ ) {
522 for ( yy=0; yy<nusize[1]; yy++ ) {
524 for ( xx=0; xx<nusize[0]; xx++, i++ ) {
526 j =
index(oldx, oldy, oldz, nn);
527 memcpy(nudata+i*elementsize, d.
uc+j*elementsize, elementsize);
538 cerr <<
tab <<
"in Bimage::enlarge" << endl;