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