#include <processor.h>
Inheritance diagram for EMAN::BooleanShrinkProcessor:
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 3254 of file processor.h.
|
Boolean shrink an image, returning the processed image.
Definition at line 2312 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. 02313 { 02314 // The basic idea of this code is to iterate through each pixel in the output image 02315 // determining its value by investigation a region of the input image 02316 02317 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02318 02319 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02320 02321 02322 int shrink = params.set_default("n",2); 02323 int search = params.set_default("search",2); 02324 02325 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02326 02327 02328 int nz = image->get_zsize(); 02329 int ny = image->get_ysize(); 02330 int nx = image->get_xsize(); 02331 02332 if (nx == 1 && ny == 1 && nz == 1 ) return image->copy(); 02333 02334 LogicOp op; 02335 EMData* return_image = new EMData(); 02336 02337 int shrinkx = shrink; 02338 int shrinky = shrink; 02339 int shrinkz = shrink; 02340 02341 int searchx = search; 02342 int searchy = search; 02343 int searchz = search; 02344 02345 // Clamping the shrink values to the dimension lengths 02346 // ensures that the return image has non zero dimensions 02347 if ( shrinkx > nx ) shrinkx = nx; 02348 if ( shrinky > ny ) shrinky = ny; 02349 if ( shrinkz > nz ) shrinkz = nz; 02350 02351 if ( nz == 1 && ny == 1 ) 02352 { 02353 return_image->set_size(nx/shrinkx); 02354 for(int i = 0; i < nx/shrinkx; ++i) 02355 { 02356 float tmp = op.get_start_val(); 02357 for(int s=0; s < searchx; ++s) 02358 { 02359 int idx = shrinkx*i+s; 02360 // Don't ask for memory beyond limits 02361 if ( idx > nx ) break; 02362 else 02363 { 02364 float val = image->get_value_at(idx); 02365 if ( op( val,tmp) ) tmp = val; 02366 } 02367 } 02368 return_image->set_value_at(i,tmp); 02369 } 02370 } 02371 else if ( nz == 1 ) 02372 { 02373 int ty = ny/shrinky; 02374 int tx = nx/shrinkx; 02375 return_image->set_size(tx,ty); 02376 for(int y = 0; y < ty; ++y) { 02377 for(int x = 0; x < tx; ++x) { 02378 float tmp = op.get_start_val(); 02379 for(int sy=0; sy < searchy; ++sy) { 02380 int yidx = shrinky*y+sy; 02381 if ( yidx >= ny) break; 02382 for(int sx=0; sx < searchx; ++sx) { 02383 int xidx = shrinkx*x+sx; 02384 if ( xidx >= nx) break; 02385 02386 float val = image->get_value_at(xidx,yidx); 02387 if ( op( val,tmp) ) tmp = val; 02388 } 02389 } 02390 return_image->set_value_at(x,y,tmp); 02391 } 02392 } 02393 } 02394 else 02395 { 02396 int tz = nz/shrinkz; 02397 int ty = ny/shrinky; 02398 int tx = nx/shrinkx; 02399 02400 return_image->set_size(tx,ty,tz); 02401 for(int z = 0; z < tz; ++z) { 02402 for(int y = 0; y < ty; ++y) { 02403 for(int x = 0; x < tx; ++x) { 02404 float tmp = op.get_start_val(); 02405 02406 for(int sz=0; sz < searchz; ++sz) { 02407 int zidx = shrinkz*z+sz; 02408 if ( zidx >= nz) break; 02409 02410 for(int sy=0; sy < searchy; ++sy) { 02411 int yidx = shrinky*y+sy; 02412 if ( yidx >= ny) break; 02413 02414 for(int sx=0; sx < searchx; ++sx) { 02415 int xidx = shrinkx*x+sx; 02416 if ( xidx >= nx) break; 02417 float val = image->get_value_at(xidx,yidx,zidx); 02418 if ( op( val,tmp) ) tmp = val; 02419 } 02420 } 02421 } 02422 return_image->set_value_at(x,y,z,tmp); 02423 } 02424 } 02425 } 02426 } 02427 return_image->update(); 02428 02429 return return_image; 02430 }
|
|
Boolean shrink an image inplace.
Definition at line 2433 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. 02434 { 02435 // The basic idea of this code is to iterate through each pixel in the output image 02436 // determining its value by investigation a region of the input image 02437 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02438 02439 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02440 02441 02442 int shrink = params.set_default("shrink",2); 02443 int search = params.set_default("search",2); 02444 02445 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02446 02447 02448 int nz = image->get_zsize(); 02449 int ny = image->get_ysize(); 02450 int nx = image->get_xsize(); 02451 02452 LogicOp op; 02453 02454 int shrinkx = shrink; 02455 int shrinky = shrink; 02456 int shrinkz = shrink; 02457 02458 int searchx = search; 02459 int searchy = search; 02460 int searchz = search; 02461 02462 // Clamping the shrink values to the dimension lengths 02463 // ensures that the return image has non zero dimensions 02464 if ( shrinkx > nx ) shrinkx = nx; 02465 if ( shrinky > ny ) shrinkx = ny; 02466 if ( shrinkz > nz ) shrinkx = nz; 02467 02468 if (nx == 1 && ny == 1 && nz == 1 ) return; 02469 02470 if ( nz == 1 && ny == 1 ) 02471 { 02472 for(int i = 0; i < nx/shrink; ++i) 02473 { 02474 float tmp = op.get_start_val(); 02475 for(int s=0; s < searchx; ++s) 02476 { 02477 int idx = shrinkx*i+s; 02478 if ( idx > nx ) break; 02479 else 02480 { 02481 float val = image->get_value_at(idx); 02482 if ( op( val,tmp) ) tmp = val; 02483 } 02484 } 02485 image->set_value_at(i,tmp); 02486 } 02487 02488 image->set_size(nx/shrinkx); 02489 } 02490 else if ( nz == 1 ) 02491 { 02492 int ty = ny/shrinky; 02493 int tx = nx/shrinkx; 02494 for(int y = 0; y < ty; ++y) { 02495 for(int x = 0; x < tx; ++x) { 02496 float tmp = op.get_start_val(); 02497 for(int sy=0; sy < searchy; ++sy) { 02498 int yidx = shrinky*y+sy; 02499 if ( yidx >= ny) break; 02500 for(int sx=0; sx < searchx; ++sx) { 02501 int xidx = shrinkx*x+sx; 02502 if ( xidx >= nx) break; 02503 02504 float val = image->get_value_at(xidx,yidx); 02505 if ( op( val,tmp) ) tmp = val; 02506 } 02507 } 02508 (*image)(x+tx*y) = tmp; 02509 } 02510 } 02511 image->set_size(tx,ty); 02512 } 02513 else 02514 { 02515 int tnxy = nx/shrinkx*ny/shrinky; 02516 int tz = nz/shrinkz; 02517 int ty = ny/shrinky; 02518 int tx = nx/shrinkx; 02519 02520 for(int z = 0; z < tz; ++z) { 02521 for(int y = 0; y < ty; ++y) { 02522 for(int x = 0; x < tx; ++x) { 02523 float tmp = op.get_start_val(); 02524 for(int sz=0; sz < searchz; ++sz) { 02525 int zidx = shrinkz*z+sz; 02526 if ( zidx >= nz) break; 02527 for(int sy=0; sy < searchy; ++sy) { 02528 int yidx = shrinky*y+sy; 02529 if ( yidx >= ny) break; 02530 for(int sx=0; sx < shrinkx; ++sx) { 02531 int xidx = shrinkx*x+sx; 02532 if ( xidx >= nx) break; 02533 02534 float val = image->get_value_at(xidx,yidx,zidx); 02535 if ( op( val,tmp) ) tmp = val; 02536 } 02537 } 02538 } 02539 (*image)(x+tx*y+tnxy*z) = tmp; 02540 } 02541 } 02542 } 02543 image->set_size(tx,ty,tz); 02544 } 02545 image->update(); 02546 }
|