#include <processor.h>

Protected Member Functions | |
| template<class LogicOp> | |
| EMData * | process (const EMData *const image, Dict ¶ms) |
| Boolean shrink an image, returning the processed image. | |
| template<class LogicOp> | |
| void | process_inplace (EMData *image, Dict ¶ms) |
| Boolean shrink an image inplace. | |
Both of these instances are written at compile time using templates.
Definition at line 3194 of file processor.h.
| EMData * BooleanShrinkProcessor::process | ( | const EMData *const | image, | |
| Dict & | params | |||
| ) | [inline, protected] |
Boolean shrink an image, returning the processed image.
| image | the image to operate on | |
| params | parameter dictionary |
| ImageFormatException | if the image is complex | |
| NullPointerException | if the image pointer is null |
Definition at line 2249 of file processor.cpp.
References EMAN::EMData::copy(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), NullPointerException, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), and x.
02250 { 02251 // The basic idea of this code is to iterate through each pixel in the output image 02252 // determining its value by investigation a region of the input image 02253 02254 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02255 02256 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02257 02258 02259 int shrink = params.set_default("n",2); 02260 int search = params.set_default("search",2); 02261 02262 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02263 02264 02265 int nz = image->get_zsize(); 02266 int ny = image->get_ysize(); 02267 int nx = image->get_xsize(); 02268 02269 if (nx == 1 && ny == 1 && nz == 1 ) return image->copy(); 02270 02271 LogicOp op; 02272 EMData* return_image = new EMData(); 02273 02274 int shrinkx = shrink; 02275 int shrinky = shrink; 02276 int shrinkz = shrink; 02277 02278 int searchx = search; 02279 int searchy = search; 02280 int searchz = search; 02281 02282 // Clamping the shrink values to the dimension lengths 02283 // ensures that the return image has non zero dimensions 02284 if ( shrinkx > nx ) shrinkx = nx; 02285 if ( shrinky > ny ) shrinky = ny; 02286 if ( shrinkz > nz ) shrinkz = nz; 02287 02288 if ( nz == 1 && ny == 1 ) 02289 { 02290 return_image->set_size(nx/shrinkx); 02291 for(int i = 0; i < nx/shrinkx; ++i) 02292 { 02293 float tmp = op.get_start_val(); 02294 for(int s=0; s < searchx; ++s) 02295 { 02296 int idx = shrinkx*i+s; 02297 // Don't ask for memory beyond limits 02298 if ( idx > nx ) break; 02299 else 02300 { 02301 float val = image->get_value_at(idx); 02302 if ( op( val,tmp) ) tmp = val; 02303 } 02304 } 02305 return_image->set_value_at(i,tmp); 02306 } 02307 } 02308 else if ( nz == 1 ) 02309 { 02310 int ty = ny/shrinky; 02311 int tx = nx/shrinkx; 02312 return_image->set_size(tx,ty); 02313 for(int y = 0; y < ty; ++y) { 02314 for(int x = 0; x < tx; ++x) { 02315 float tmp = op.get_start_val(); 02316 for(int sy=0; sy < searchy; ++sy) { 02317 int yidx = shrinky*y+sy; 02318 if ( yidx >= ny) break; 02319 for(int sx=0; sx < searchx; ++sx) { 02320 int xidx = shrinkx*x+sx; 02321 if ( xidx >= nx) break; 02322 02323 float val = image->get_value_at(xidx,yidx); 02324 if ( op( val,tmp) ) tmp = val; 02325 } 02326 } 02327 return_image->set_value_at(x,y,tmp); 02328 } 02329 } 02330 } 02331 else 02332 { 02333 int tz = nz/shrinkz; 02334 int ty = ny/shrinky; 02335 int tx = nx/shrinkx; 02336 02337 return_image->set_size(tx,ty,tz); 02338 for(int z = 0; z < tz; ++z) { 02339 for(int y = 0; y < ty; ++y) { 02340 for(int x = 0; x < tx; ++x) { 02341 float tmp = op.get_start_val(); 02342 02343 for(int sz=0; sz < searchz; ++sz) { 02344 int zidx = shrinkz*z+sz; 02345 if ( zidx >= nz) break; 02346 02347 for(int sy=0; sy < searchy; ++sy) { 02348 int yidx = shrinky*y+sy; 02349 if ( yidx >= ny) break; 02350 02351 for(int sx=0; sx < searchx; ++sx) { 02352 int xidx = shrinkx*x+sx; 02353 if ( xidx >= nx) break; 02354 float val = image->get_value_at(xidx,yidx,zidx); 02355 if ( op( val,tmp) ) tmp = val; 02356 } 02357 } 02358 } 02359 return_image->set_value_at(x,y,z,tmp); 02360 } 02361 } 02362 } 02363 } 02364 return_image->update(); 02365 02366 return return_image; 02367 }
| void BooleanShrinkProcessor::process_inplace | ( | EMData * | image, | |
| Dict & | params | |||
| ) | [inline, protected] |
Boolean shrink an image inplace.
| image | the image to operate on | |
| params | parameter dictionary |
| ImageFormatException | if the image is complex | |
| NullPointerException | if the image pointer is null |
Definition at line 2370 of file processor.cpp.
References EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, InvalidValueException, EMAN::EMData::is_complex(), NullPointerException, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), and x.
02371 { 02372 // The basic idea of this code is to iterate through each pixel in the output image 02373 // determining its value by investigation a region of the input image 02374 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02375 02376 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02377 02378 02379 int shrink = params.set_default("shrink",2); 02380 int search = params.set_default("search",2); 02381 02382 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02383 02384 02385 int nz = image->get_zsize(); 02386 int ny = image->get_ysize(); 02387 int nx = image->get_xsize(); 02388 02389 LogicOp op; 02390 02391 int shrinkx = shrink; 02392 int shrinky = shrink; 02393 int shrinkz = shrink; 02394 02395 int searchx = search; 02396 int searchy = search; 02397 int searchz = search; 02398 02399 // Clamping the shrink values to the dimension lengths 02400 // ensures that the return image has non zero dimensions 02401 if ( shrinkx > nx ) shrinkx = nx; 02402 if ( shrinky > ny ) shrinkx = ny; 02403 if ( shrinkz > nz ) shrinkx = nz; 02404 02405 if (nx == 1 && ny == 1 && nz == 1 ) return; 02406 02407 if ( nz == 1 && ny == 1 ) 02408 { 02409 for(int i = 0; i < nx/shrink; ++i) 02410 { 02411 float tmp = op.get_start_val(); 02412 for(int s=0; s < searchx; ++s) 02413 { 02414 int idx = shrinkx*i+s; 02415 if ( idx > nx ) break; 02416 else 02417 { 02418 float val = image->get_value_at(idx); 02419 if ( op( val,tmp) ) tmp = val; 02420 } 02421 } 02422 image->set_value_at(i,tmp); 02423 } 02424 02425 image->set_size(nx/shrinkx); 02426 } 02427 else if ( nz == 1 ) 02428 { 02429 int ty = ny/shrinky; 02430 int tx = nx/shrinkx; 02431 for(int y = 0; y < ty; ++y) { 02432 for(int x = 0; x < tx; ++x) { 02433 float tmp = op.get_start_val(); 02434 for(int sy=0; sy < searchy; ++sy) { 02435 int yidx = shrinky*y+sy; 02436 if ( yidx >= ny) break; 02437 for(int sx=0; sx < searchx; ++sx) { 02438 int xidx = shrinkx*x+sx; 02439 if ( xidx >= nx) break; 02440 02441 float val = image->get_value_at(xidx,yidx); 02442 if ( op( val,tmp) ) tmp = val; 02443 } 02444 } 02445 (*image)(x+tx*y) = tmp; 02446 } 02447 } 02448 image->set_size(tx,ty); 02449 } 02450 else 02451 { 02452 int tnxy = nx/shrinkx*ny/shrinky; 02453 int tz = nz/shrinkz; 02454 int ty = ny/shrinky; 02455 int tx = nx/shrinkx; 02456 02457 for(int z = 0; z < tz; ++z) { 02458 for(int y = 0; y < ty; ++y) { 02459 for(int x = 0; x < tx; ++x) { 02460 float tmp = op.get_start_val(); 02461 for(int sz=0; sz < searchz; ++sz) { 02462 int zidx = shrinkz*z+sz; 02463 if ( zidx >= nz) break; 02464 for(int sy=0; sy < searchy; ++sy) { 02465 int yidx = shrinky*y+sy; 02466 if ( yidx >= ny) break; 02467 for(int sx=0; sx < shrinkx; ++sx) { 02468 int xidx = shrinkx*x+sx; 02469 if ( xidx >= nx) break; 02470 02471 float val = image->get_value_at(xidx,yidx,zidx); 02472 if ( op( val,tmp) ) tmp = val; 02473 } 02474 } 02475 } 02476 (*image)(x+tx*y+tnxy*z) = tmp; 02477 } 02478 } 02479 } 02480 image->set_size(tx,ty,tz); 02481 } 02482 image->update(); 02483 }
1.5.6