Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::BooleanShrinkProcessor Class Reference

BooleanShrinkProcessor encapsulates code common to MaxShrinkProcessor and MinShrinkProcessor - the processors use more or less identical code, the main difference being the logical operator. More...

#include <processor.h>

Inheritance diagram for EMAN::BooleanShrinkProcessor:

Inheritance graph
[legend]
List of all members.

Protected Member Functions

template<class LogicOp>
EMDataprocess (const EMData *const image, Dict &params)
 Boolean shrink an image, returning the processed image.
template<class LogicOp>
void process_inplace (EMData *image, Dict &params)
 Boolean shrink an image inplace.

Detailed Description

BooleanShrinkProcessor encapsulates code common to MaxShrinkProcessor and MinShrinkProcessor - the processors use more or less identical code, the main difference being the logical operator.

Both of these instances are written at compile time using templates.

Definition at line 3300 of file processor.h.


Member Function Documentation

template<class LogicOp>
EMData * BooleanShrinkProcessor::process const EMData *const   image,
Dict params
[protected]
 

Boolean shrink an image, returning the processed image.

Parameters:
image the image to operate on
params parameter dictionary
Exceptions:
ImageFormatException if the image is complex
NullPointerException if the image pointer is null
Returns:
the image that results from the operation

Definition at line 2400 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, nx, ny, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), x, and y.

02401 {
02402         // The basic idea of this code is to iterate through each pixel in the output image
02403         // determining its value by investigation a region of the input image
02404 
02405         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02406 
02407         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02408 
02409 
02410         int shrink = params.set_default("n",2);
02411         int search = params.set_default("search",2);
02412 
02413         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02414 
02415 
02416         int nz = image->get_zsize();
02417         int ny = image->get_ysize();
02418         int nx = image->get_xsize();
02419 
02420         if (nx == 1 && ny == 1 && nz == 1 ) return image->copy();
02421 
02422         LogicOp op;
02423         EMData* return_image = new EMData();
02424 
02425         int shrinkx = shrink;
02426         int shrinky = shrink;
02427         int shrinkz = shrink;
02428 
02429         int searchx = search;
02430         int searchy = search;
02431         int searchz = search;
02432 
02433         // Clamping the shrink values to the dimension lengths
02434         // ensures that the return image has non zero dimensions
02435         if ( shrinkx > nx ) shrinkx = nx;
02436         if ( shrinky > ny ) shrinky = ny;
02437         if ( shrinkz > nz ) shrinkz = nz;
02438 
02439         if ( nz == 1 && ny == 1 )
02440         {
02441                 return_image->set_size(nx/shrinkx);
02442                 for(int i = 0; i < nx/shrinkx; ++i)
02443                 {
02444                         float tmp = op.get_start_val();
02445                         for(int s=0; s < searchx; ++s)
02446                         {
02447                                 int idx = shrinkx*i+s;
02448                                 // Don't ask for memory beyond limits
02449                                 if ( idx > nx ) break;
02450                                 else
02451                                 {
02452                                         float val = image->get_value_at(idx);
02453                                         if ( op( val,tmp) ) tmp = val;
02454                                 }
02455                         }
02456                         return_image->set_value_at(i,tmp);
02457                 }
02458         }
02459         else if ( nz == 1 )
02460         {
02461                 int ty = ny/shrinky;
02462                 int tx = nx/shrinkx;
02463                 return_image->set_size(tx,ty);
02464                 for(int y = 0; y < ty; ++y) {
02465                         for(int x = 0; x < tx; ++x) {
02466                                 float tmp = op.get_start_val();
02467                                 for(int sy=0; sy < searchy; ++sy) {
02468                                         int yidx = shrinky*y+sy;
02469                                         if ( yidx >= ny) break;
02470                                         for(int sx=0; sx < searchx; ++sx) {
02471                                                 int xidx = shrinkx*x+sx;
02472                                                 if ( xidx >= nx) break;
02473 
02474                                                 float val = image->get_value_at(xidx,yidx);
02475                                                 if ( op( val,tmp) ) tmp = val;
02476                                         }
02477                                 }
02478                                 return_image->set_value_at(x,y,tmp);
02479                         }
02480                 }
02481         }
02482         else
02483         {
02484                 int tz = nz/shrinkz;
02485                 int ty = ny/shrinky;
02486                 int tx = nx/shrinkx;
02487 
02488                 return_image->set_size(tx,ty,tz);
02489                 for(int z = 0; z < tz; ++z) {
02490                         for(int y = 0; y < ty; ++y) {
02491                                 for(int x = 0; x < tx; ++x) {
02492                                         float tmp = op.get_start_val();
02493 
02494                                         for(int sz=0; sz < searchz; ++sz) {
02495                                                 int zidx = shrinkz*z+sz;
02496                                                 if ( zidx >= nz) break;
02497 
02498                                                 for(int sy=0; sy < searchy; ++sy) {
02499                                                         int yidx = shrinky*y+sy;
02500                                                         if ( yidx >= ny) break;
02501 
02502                                                         for(int sx=0; sx < searchx; ++sx) {
02503                                                                 int xidx = shrinkx*x+sx;
02504                                                                 if ( xidx >= nx) break;
02505                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02506                                                                 if ( op( val,tmp) ) tmp = val;
02507                                                         }
02508                                                 }
02509                                         }
02510                                         return_image->set_value_at(x,y,z,tmp);
02511                                 }
02512                         }
02513                 }
02514         }
02515         return_image->update();
02516 
02517         return return_image;
02518 }

template<class LogicOp>
void BooleanShrinkProcessor::process_inplace EMData image,
Dict params
[protected]
 

Boolean shrink an image inplace.

Parameters:
image the image to operate on
params parameter dictionary
Exceptions:
ImageFormatException if the image is complex
NullPointerException if the image pointer is null

Definition at line 2521 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, nx, ny, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at(), EMAN::EMData::update(), x, and y.

02522 {
02523         // The basic idea of this code is to iterate through each pixel in the output image
02524         // determining its value by investigation a region of the input image
02525         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02526 
02527         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02528 
02529 
02530         int shrink = params.set_default("shrink",2);
02531         int search = params.set_default("search",2);
02532 
02533         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02534 
02535 
02536         int nz = image->get_zsize();
02537         int ny = image->get_ysize();
02538         int nx = image->get_xsize();
02539 
02540         LogicOp op;
02541 
02542         int shrinkx = shrink;
02543         int shrinky = shrink;
02544         int shrinkz = shrink;
02545 
02546         int searchx = search;
02547         int searchy = search;
02548         int searchz = search;
02549 
02550         // Clamping the shrink values to the dimension lengths
02551         // ensures that the return image has non zero dimensions
02552         if ( shrinkx > nx ) shrinkx = nx;
02553         if ( shrinky > ny ) shrinkx = ny;
02554         if ( shrinkz > nz ) shrinkx = nz;
02555 
02556         if (nx == 1 && ny == 1 && nz == 1 ) return;
02557 
02558         if ( nz == 1 && ny == 1 )
02559         {
02560                 for(int i = 0; i < nx/shrink; ++i)
02561                 {
02562                         float tmp = op.get_start_val();
02563                         for(int s=0; s < searchx; ++s)
02564                         {
02565                                 int idx = shrinkx*i+s;
02566                                 if ( idx > nx ) break;
02567                                 else
02568                                 {
02569                                         float val = image->get_value_at(idx);
02570                                         if ( op( val,tmp) ) tmp = val;
02571                                 }
02572                         }
02573                         image->set_value_at(i,tmp);
02574                 }
02575 
02576                 image->set_size(nx/shrinkx);
02577         }
02578         else if ( nz == 1 )
02579         {
02580                 int ty = ny/shrinky;
02581                 int tx = nx/shrinkx;
02582                 for(int y = 0; y < ty; ++y) {
02583                         for(int x = 0; x < tx; ++x) {
02584                                 float tmp = op.get_start_val();
02585                                 for(int sy=0; sy < searchy; ++sy) {
02586                                         int yidx = shrinky*y+sy;
02587                                         if ( yidx >= ny) break;
02588                                         for(int sx=0; sx < searchx; ++sx) {
02589                                                 int xidx = shrinkx*x+sx;
02590                                                 if ( xidx >= nx) break;
02591 
02592                                                 float val = image->get_value_at(xidx,yidx);
02593                                                 if ( op( val,tmp) ) tmp = val;
02594                                         }
02595                                 }
02596                                 (*image)(x+tx*y) = tmp;
02597                         }
02598                 }
02599                 image->set_size(tx,ty);
02600         }
02601         else
02602         {
02603                 int tnxy = nx/shrinkx*ny/shrinky;
02604                 int tz = nz/shrinkz;
02605                 int ty = ny/shrinky;
02606                 int tx = nx/shrinkx;
02607 
02608                 for(int z = 0; z < tz; ++z) {
02609                         for(int y = 0; y < ty; ++y) {
02610                                 for(int x = 0; x < tx; ++x) {
02611                                         float tmp = op.get_start_val();
02612                                         for(int sz=0; sz < searchz; ++sz) {
02613                                                 int zidx = shrinkz*z+sz;
02614                                                 if ( zidx >= nz) break;
02615                                                 for(int sy=0; sy < searchy; ++sy) {
02616                                                         int yidx = shrinky*y+sy;
02617                                                         if ( yidx >= ny) break;
02618                                                         for(int sx=0; sx < shrinkx; ++sx) {
02619                                                                 int xidx = shrinkx*x+sx;
02620                                                                 if ( xidx >= nx) break;
02621 
02622                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02623                                                                 if ( op( val,tmp) ) tmp = val;
02624                                                         }
02625                                                 }
02626                                         }
02627                                         (*image)(x+tx*y+tnxy*z) = tmp;
02628                                 }
02629                         }
02630                 }
02631                 image->set_size(tx,ty,tz);
02632         }
02633         image->update();
02634 }


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:43 2013 for EMAN2 by  doxygen 1.3.9.1