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