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 3219 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 2359 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.

02360 {
02361         // The basic idea of this code is to iterate through each pixel in the output image
02362         // determining its value by investigation a region of the input image
02363 
02364         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02365 
02366         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02367 
02368 
02369         int shrink = params.set_default("n",2);
02370         int search = params.set_default("search",2);
02371 
02372         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02373 
02374 
02375         int nz = image->get_zsize();
02376         int ny = image->get_ysize();
02377         int nx = image->get_xsize();
02378 
02379         if (nx == 1 && ny == 1 && nz == 1 ) return image->copy();
02380 
02381         LogicOp op;
02382         EMData* return_image = new EMData();
02383 
02384         int shrinkx = shrink;
02385         int shrinky = shrink;
02386         int shrinkz = shrink;
02387 
02388         int searchx = search;
02389         int searchy = search;
02390         int searchz = search;
02391 
02392         // Clamping the shrink values to the dimension lengths
02393         // ensures that the return image has non zero dimensions
02394         if ( shrinkx > nx ) shrinkx = nx;
02395         if ( shrinky > ny ) shrinky = ny;
02396         if ( shrinkz > nz ) shrinkz = nz;
02397 
02398         if ( nz == 1 && ny == 1 )
02399         {
02400                 return_image->set_size(nx/shrinkx);
02401                 for(int i = 0; i < nx/shrinkx; ++i)
02402                 {
02403                         float tmp = op.get_start_val();
02404                         for(int s=0; s < searchx; ++s)
02405                         {
02406                                 int idx = shrinkx*i+s;
02407                                 // Don't ask for memory beyond limits
02408                                 if ( idx > nx ) break;
02409                                 else
02410                                 {
02411                                         float val = image->get_value_at(idx);
02412                                         if ( op( val,tmp) ) tmp = val;
02413                                 }
02414                         }
02415                         return_image->set_value_at(i,tmp);
02416                 }
02417         }
02418         else if ( nz == 1 )
02419         {
02420                 int ty = ny/shrinky;
02421                 int tx = nx/shrinkx;
02422                 return_image->set_size(tx,ty);
02423                 for(int y = 0; y < ty; ++y) {
02424                         for(int x = 0; x < tx; ++x) {
02425                                 float tmp = op.get_start_val();
02426                                 for(int sy=0; sy < searchy; ++sy) {
02427                                         int yidx = shrinky*y+sy;
02428                                         if ( yidx >= ny) break;
02429                                         for(int sx=0; sx < searchx; ++sx) {
02430                                                 int xidx = shrinkx*x+sx;
02431                                                 if ( xidx >= nx) break;
02432 
02433                                                 float val = image->get_value_at(xidx,yidx);
02434                                                 if ( op( val,tmp) ) tmp = val;
02435                                         }
02436                                 }
02437                                 return_image->set_value_at(x,y,tmp);
02438                         }
02439                 }
02440         }
02441         else
02442         {
02443                 int tz = nz/shrinkz;
02444                 int ty = ny/shrinky;
02445                 int tx = nx/shrinkx;
02446 
02447                 return_image->set_size(tx,ty,tz);
02448                 for(int z = 0; z < tz; ++z) {
02449                         for(int y = 0; y < ty; ++y) {
02450                                 for(int x = 0; x < tx; ++x) {
02451                                         float tmp = op.get_start_val();
02452 
02453                                         for(int sz=0; sz < searchz; ++sz) {
02454                                                 int zidx = shrinkz*z+sz;
02455                                                 if ( zidx >= nz) break;
02456 
02457                                                 for(int sy=0; sy < searchy; ++sy) {
02458                                                         int yidx = shrinky*y+sy;
02459                                                         if ( yidx >= ny) break;
02460 
02461                                                         for(int sx=0; sx < searchx; ++sx) {
02462                                                                 int xidx = shrinkx*x+sx;
02463                                                                 if ( xidx >= nx) break;
02464                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02465                                                                 if ( op( val,tmp) ) tmp = val;
02466                                                         }
02467                                                 }
02468                                         }
02469                                         return_image->set_value_at(x,y,z,tmp);
02470                                 }
02471                         }
02472                 }
02473         }
02474         return_image->update();
02475 
02476         return return_image;
02477 }

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 2480 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.

02481 {
02482         // The basic idea of this code is to iterate through each pixel in the output image
02483         // determining its value by investigation a region of the input image
02484         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02485 
02486         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02487 
02488 
02489         int shrink = params.set_default("shrink",2);
02490         int search = params.set_default("search",2);
02491 
02492         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02493 
02494 
02495         int nz = image->get_zsize();
02496         int ny = image->get_ysize();
02497         int nx = image->get_xsize();
02498 
02499         LogicOp op;
02500 
02501         int shrinkx = shrink;
02502         int shrinky = shrink;
02503         int shrinkz = shrink;
02504 
02505         int searchx = search;
02506         int searchy = search;
02507         int searchz = search;
02508 
02509         // Clamping the shrink values to the dimension lengths
02510         // ensures that the return image has non zero dimensions
02511         if ( shrinkx > nx ) shrinkx = nx;
02512         if ( shrinky > ny ) shrinkx = ny;
02513         if ( shrinkz > nz ) shrinkx = nz;
02514 
02515         if (nx == 1 && ny == 1 && nz == 1 ) return;
02516 
02517         if ( nz == 1 && ny == 1 )
02518         {
02519                 for(int i = 0; i < nx/shrink; ++i)
02520                 {
02521                         float tmp = op.get_start_val();
02522                         for(int s=0; s < searchx; ++s)
02523                         {
02524                                 int idx = shrinkx*i+s;
02525                                 if ( idx > nx ) break;
02526                                 else
02527                                 {
02528                                         float val = image->get_value_at(idx);
02529                                         if ( op( val,tmp) ) tmp = val;
02530                                 }
02531                         }
02532                         image->set_value_at(i,tmp);
02533                 }
02534 
02535                 image->set_size(nx/shrinkx);
02536         }
02537         else if ( nz == 1 )
02538         {
02539                 int ty = ny/shrinky;
02540                 int tx = nx/shrinkx;
02541                 for(int y = 0; y < ty; ++y) {
02542                         for(int x = 0; x < tx; ++x) {
02543                                 float tmp = op.get_start_val();
02544                                 for(int sy=0; sy < searchy; ++sy) {
02545                                         int yidx = shrinky*y+sy;
02546                                         if ( yidx >= ny) break;
02547                                         for(int sx=0; sx < searchx; ++sx) {
02548                                                 int xidx = shrinkx*x+sx;
02549                                                 if ( xidx >= nx) break;
02550 
02551                                                 float val = image->get_value_at(xidx,yidx);
02552                                                 if ( op( val,tmp) ) tmp = val;
02553                                         }
02554                                 }
02555                                 (*image)(x+tx*y) = tmp;
02556                         }
02557                 }
02558                 image->set_size(tx,ty);
02559         }
02560         else
02561         {
02562                 int tnxy = nx/shrinkx*ny/shrinky;
02563                 int tz = nz/shrinkz;
02564                 int ty = ny/shrinky;
02565                 int tx = nx/shrinkx;
02566 
02567                 for(int z = 0; z < tz; ++z) {
02568                         for(int y = 0; y < ty; ++y) {
02569                                 for(int x = 0; x < tx; ++x) {
02570                                         float tmp = op.get_start_val();
02571                                         for(int sz=0; sz < searchz; ++sz) {
02572                                                 int zidx = shrinkz*z+sz;
02573                                                 if ( zidx >= nz) break;
02574                                                 for(int sy=0; sy < searchy; ++sy) {
02575                                                         int yidx = shrinky*y+sy;
02576                                                         if ( yidx >= ny) break;
02577                                                         for(int sx=0; sx < shrinkx; ++sx) {
02578                                                                 int xidx = shrinkx*x+sx;
02579                                                                 if ( xidx >= nx) break;
02580 
02581                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02582                                                                 if ( op( val,tmp) ) tmp = val;
02583                                                         }
02584                                                 }
02585                                         }
02586                                         (*image)(x+tx*y+tnxy*z) = tmp;
02587                                 }
02588                         }
02589                 }
02590                 image->set_size(tx,ty,tz);
02591         }
02592         image->update();
02593 }


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:19 2011 for EMAN2 by  doxygen 1.3.9.1