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