#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 3257 of file processor.h.
EMData * BooleanShrinkProcessor::process | ( | const EMData *const | image, | |
Dict & | params | |||
) | [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 2387 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.
02388 { 02389 // The basic idea of this code is to iterate through each pixel in the output image 02390 // determining its value by investigation a region of the input image 02391 02392 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02393 02394 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02395 02396 02397 int shrink = params.set_default("n",2); 02398 int search = params.set_default("search",2); 02399 02400 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02401 02402 02403 int nz = image->get_zsize(); 02404 int ny = image->get_ysize(); 02405 int nx = image->get_xsize(); 02406 02407 if (nx == 1 && ny == 1 && nz == 1 ) return image->copy(); 02408 02409 LogicOp op; 02410 EMData* return_image = new EMData(); 02411 02412 int shrinkx = shrink; 02413 int shrinky = shrink; 02414 int shrinkz = shrink; 02415 02416 int searchx = search; 02417 int searchy = search; 02418 int searchz = search; 02419 02420 // Clamping the shrink values to the dimension lengths 02421 // ensures that the return image has non zero dimensions 02422 if ( shrinkx > nx ) shrinkx = nx; 02423 if ( shrinky > ny ) shrinky = ny; 02424 if ( shrinkz > nz ) shrinkz = nz; 02425 02426 if ( nz == 1 && ny == 1 ) 02427 { 02428 return_image->set_size(nx/shrinkx); 02429 for(int i = 0; i < nx/shrinkx; ++i) 02430 { 02431 float tmp = op.get_start_val(); 02432 for(int s=0; s < searchx; ++s) 02433 { 02434 int idx = shrinkx*i+s; 02435 // Don't ask for memory beyond limits 02436 if ( idx > nx ) break; 02437 else 02438 { 02439 float val = image->get_value_at(idx); 02440 if ( op( val,tmp) ) tmp = val; 02441 } 02442 } 02443 return_image->set_value_at(i,tmp); 02444 } 02445 } 02446 else if ( nz == 1 ) 02447 { 02448 int ty = ny/shrinky; 02449 int tx = nx/shrinkx; 02450 return_image->set_size(tx,ty); 02451 for(int y = 0; y < ty; ++y) { 02452 for(int x = 0; x < tx; ++x) { 02453 float tmp = op.get_start_val(); 02454 for(int sy=0; sy < searchy; ++sy) { 02455 int yidx = shrinky*y+sy; 02456 if ( yidx >= ny) break; 02457 for(int sx=0; sx < searchx; ++sx) { 02458 int xidx = shrinkx*x+sx; 02459 if ( xidx >= nx) break; 02460 02461 float val = image->get_value_at(xidx,yidx); 02462 if ( op( val,tmp) ) tmp = val; 02463 } 02464 } 02465 return_image->set_value_at(x,y,tmp); 02466 } 02467 } 02468 } 02469 else 02470 { 02471 int tz = nz/shrinkz; 02472 int ty = ny/shrinky; 02473 int tx = nx/shrinkx; 02474 02475 return_image->set_size(tx,ty,tz); 02476 for(int z = 0; z < tz; ++z) { 02477 for(int y = 0; y < ty; ++y) { 02478 for(int x = 0; x < tx; ++x) { 02479 float tmp = op.get_start_val(); 02480 02481 for(int sz=0; sz < searchz; ++sz) { 02482 int zidx = shrinkz*z+sz; 02483 if ( zidx >= nz) break; 02484 02485 for(int sy=0; sy < searchy; ++sy) { 02486 int yidx = shrinky*y+sy; 02487 if ( yidx >= ny) break; 02488 02489 for(int sx=0; sx < searchx; ++sx) { 02490 int xidx = shrinkx*x+sx; 02491 if ( xidx >= nx) break; 02492 float val = image->get_value_at(xidx,yidx,zidx); 02493 if ( op( val,tmp) ) tmp = val; 02494 } 02495 } 02496 } 02497 return_image->set_value_at(x,y,z,tmp); 02498 } 02499 } 02500 } 02501 } 02502 return_image->update(); 02503 02504 return return_image; 02505 }
void BooleanShrinkProcessor::process_inplace | ( | EMData * | image, | |
Dict & | params | |||
) | [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 2508 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.
02509 { 02510 // The basic idea of this code is to iterate through each pixel in the output image 02511 // determining its value by investigation a region of the input image 02512 if (!image) throw NullPointerException("Attempt to max shrink a null image"); 02513 02514 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image"); 02515 02516 02517 int shrink = params.set_default("shrink",2); 02518 int search = params.set_default("search",2); 02519 02520 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0"); 02521 02522 02523 int nz = image->get_zsize(); 02524 int ny = image->get_ysize(); 02525 int nx = image->get_xsize(); 02526 02527 LogicOp op; 02528 02529 int shrinkx = shrink; 02530 int shrinky = shrink; 02531 int shrinkz = shrink; 02532 02533 int searchx = search; 02534 int searchy = search; 02535 int searchz = search; 02536 02537 // Clamping the shrink values to the dimension lengths 02538 // ensures that the return image has non zero dimensions 02539 if ( shrinkx > nx ) shrinkx = nx; 02540 if ( shrinky > ny ) shrinkx = ny; 02541 if ( shrinkz > nz ) shrinkx = nz; 02542 02543 if (nx == 1 && ny == 1 && nz == 1 ) return; 02544 02545 if ( nz == 1 && ny == 1 ) 02546 { 02547 for(int i = 0; i < nx/shrink; ++i) 02548 { 02549 float tmp = op.get_start_val(); 02550 for(int s=0; s < searchx; ++s) 02551 { 02552 int idx = shrinkx*i+s; 02553 if ( idx > nx ) break; 02554 else 02555 { 02556 float val = image->get_value_at(idx); 02557 if ( op( val,tmp) ) tmp = val; 02558 } 02559 } 02560 image->set_value_at(i,tmp); 02561 } 02562 02563 image->set_size(nx/shrinkx); 02564 } 02565 else if ( nz == 1 ) 02566 { 02567 int ty = ny/shrinky; 02568 int tx = nx/shrinkx; 02569 for(int y = 0; y < ty; ++y) { 02570 for(int x = 0; x < tx; ++x) { 02571 float tmp = op.get_start_val(); 02572 for(int sy=0; sy < searchy; ++sy) { 02573 int yidx = shrinky*y+sy; 02574 if ( yidx >= ny) break; 02575 for(int sx=0; sx < searchx; ++sx) { 02576 int xidx = shrinkx*x+sx; 02577 if ( xidx >= nx) break; 02578 02579 float val = image->get_value_at(xidx,yidx); 02580 if ( op( val,tmp) ) tmp = val; 02581 } 02582 } 02583 (*image)(x+tx*y) = tmp; 02584 } 02585 } 02586 image->set_size(tx,ty); 02587 } 02588 else 02589 { 02590 int tnxy = nx/shrinkx*ny/shrinky; 02591 int tz = nz/shrinkz; 02592 int ty = ny/shrinky; 02593 int tx = nx/shrinkx; 02594 02595 for(int z = 0; z < tz; ++z) { 02596 for(int y = 0; y < ty; ++y) { 02597 for(int x = 0; x < tx; ++x) { 02598 float tmp = op.get_start_val(); 02599 for(int sz=0; sz < searchz; ++sz) { 02600 int zidx = shrinkz*z+sz; 02601 if ( zidx >= nz) break; 02602 for(int sy=0; sy < searchy; ++sy) { 02603 int yidx = shrinky*y+sy; 02604 if ( yidx >= ny) break; 02605 for(int sx=0; sx < shrinkx; ++sx) { 02606 int xidx = shrinkx*x+sx; 02607 if ( xidx >= nx) break; 02608 02609 float val = image->get_value_at(xidx,yidx,zidx); 02610 if ( op( val,tmp) ) tmp = val; 02611 } 02612 } 02613 } 02614 (*image)(x+tx*y+tnxy*z) = tmp; 02615 } 02616 } 02617 } 02618 image->set_size(tx,ty,tz); 02619 } 02620 image->update(); 02621 }