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 3078 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 2267 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.

02268 {
02269         // The basic idea of this code is to iterate through each pixel in the output image
02270         // determining its value by investigation a region of the input image
02271 
02272         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02273 
02274         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02275 
02276 
02277         int shrink = params.set_default("n",2);
02278         int search = params.set_default("search",2);
02279 
02280         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02281 
02282 
02283         int nz = image->get_zsize();
02284         int ny = image->get_ysize();
02285         int nx = image->get_xsize();
02286 
02287         if (nx == 1 && ny == 1 && nz == 1 ) return image->copy();
02288 
02289         LogicOp op;
02290         EMData* return_image = new EMData();
02291 
02292         int shrinkx = shrink;
02293         int shrinky = shrink;
02294         int shrinkz = shrink;
02295 
02296         int searchx = search;
02297         int searchy = search;
02298         int searchz = search;
02299 
02300         // Clamping the shrink values to the dimension lengths
02301         // ensures that the return image has non zero dimensions
02302         if ( shrinkx > nx ) shrinkx = nx;
02303         if ( shrinky > ny ) shrinky = ny;
02304         if ( shrinkz > nz ) shrinkz = nz;
02305 
02306         if ( nz == 1 && ny == 1 )
02307         {
02308                 return_image->set_size(nx/shrinkx);
02309                 for(int i = 0; i < nx/shrinkx; ++i)
02310                 {
02311                         float tmp = op.get_start_val();
02312                         for(int s=0; s < searchx; ++s)
02313                         {
02314                                 int idx = shrinkx*i+s;
02315                                 // Don't ask for memory beyond limits
02316                                 if ( idx > nx ) break;
02317                                 else
02318                                 {
02319                                         float val = image->get_value_at(idx);
02320                                         if ( op( val,tmp) ) tmp = val;
02321                                 }
02322                         }
02323                         return_image->set_value_at(i,tmp);
02324                 }
02325         }
02326         else if ( nz == 1 )
02327         {
02328                 int ty = ny/shrinky;
02329                 int tx = nx/shrinkx;
02330                 return_image->set_size(tx,ty);
02331                 for(int y = 0; y < ty; ++y) {
02332                         for(int x = 0; x < tx; ++x) {
02333                                 float tmp = op.get_start_val();
02334                                 for(int sy=0; sy < searchy; ++sy) {
02335                                         int yidx = shrinky*y+sy;
02336                                         if ( yidx >= ny) break;
02337                                         for(int sx=0; sx < searchx; ++sx) {
02338                                                 int xidx = shrinkx*x+sx;
02339                                                 if ( xidx >= nx) break;
02340 
02341                                                 float val = image->get_value_at(xidx,yidx);
02342                                                 if ( op( val,tmp) ) tmp = val;
02343                                         }
02344                                 }
02345                                 return_image->set_value_at(x,y,tmp);
02346                         }
02347                 }
02348         }
02349         else
02350         {
02351                 int tz = nz/shrinkz;
02352                 int ty = ny/shrinky;
02353                 int tx = nx/shrinkx;
02354 
02355                 return_image->set_size(tx,ty,tz);
02356                 for(int z = 0; z < tz; ++z) {
02357                         for(int y = 0; y < ty; ++y) {
02358                                 for(int x = 0; x < tx; ++x) {
02359                                         float tmp = op.get_start_val();
02360 
02361                                         for(int sz=0; sz < searchz; ++sz) {
02362                                                 int zidx = shrinkz*z+sz;
02363                                                 if ( zidx >= nz) break;
02364 
02365                                                 for(int sy=0; sy < searchy; ++sy) {
02366                                                         int yidx = shrinky*y+sy;
02367                                                         if ( yidx >= ny) break;
02368 
02369                                                         for(int sx=0; sx < searchx; ++sx) {
02370                                                                 int xidx = shrinkx*x+sx;
02371                                                                 if ( xidx >= nx) break;
02372                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02373                                                                 if ( op( val,tmp) ) tmp = val;
02374                                                         }
02375                                                 }
02376                                         }
02377                                         return_image->set_value_at(x,y,z,tmp);
02378                                 }
02379                         }
02380                 }
02381         }
02382         return_image->update();
02383 
02384         return return_image;
02385 }

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

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


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:47:57 2010 for EMAN2 by  doxygen 1.3.9.1