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 3253 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 2322 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.

02323 {
02324         // The basic idea of this code is to iterate through each pixel in the output image
02325         // determining its value by investigation a region of the input image
02326 
02327         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02328 
02329         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02330 
02331 
02332         int shrink = params.set_default("n",2);
02333         int search = params.set_default("search",2);
02334 
02335         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02336 
02337 
02338         int nz = image->get_zsize();
02339         int ny = image->get_ysize();
02340         int nx = image->get_xsize();
02341 
02342         if (nx == 1 && ny == 1 && nz == 1 ) return image->copy();
02343 
02344         LogicOp op;
02345         EMData* return_image = new EMData();
02346 
02347         int shrinkx = shrink;
02348         int shrinky = shrink;
02349         int shrinkz = shrink;
02350 
02351         int searchx = search;
02352         int searchy = search;
02353         int searchz = search;
02354 
02355         // Clamping the shrink values to the dimension lengths
02356         // ensures that the return image has non zero dimensions
02357         if ( shrinkx > nx ) shrinkx = nx;
02358         if ( shrinky > ny ) shrinky = ny;
02359         if ( shrinkz > nz ) shrinkz = nz;
02360 
02361         if ( nz == 1 && ny == 1 )
02362         {
02363                 return_image->set_size(nx/shrinkx);
02364                 for(int i = 0; i < nx/shrinkx; ++i)
02365                 {
02366                         float tmp = op.get_start_val();
02367                         for(int s=0; s < searchx; ++s)
02368                         {
02369                                 int idx = shrinkx*i+s;
02370                                 // Don't ask for memory beyond limits
02371                                 if ( idx > nx ) break;
02372                                 else
02373                                 {
02374                                         float val = image->get_value_at(idx);
02375                                         if ( op( val,tmp) ) tmp = val;
02376                                 }
02377                         }
02378                         return_image->set_value_at(i,tmp);
02379                 }
02380         }
02381         else if ( nz == 1 )
02382         {
02383                 int ty = ny/shrinky;
02384                 int tx = nx/shrinkx;
02385                 return_image->set_size(tx,ty);
02386                 for(int y = 0; y < ty; ++y) {
02387                         for(int x = 0; x < tx; ++x) {
02388                                 float tmp = op.get_start_val();
02389                                 for(int sy=0; sy < searchy; ++sy) {
02390                                         int yidx = shrinky*y+sy;
02391                                         if ( yidx >= ny) break;
02392                                         for(int sx=0; sx < searchx; ++sx) {
02393                                                 int xidx = shrinkx*x+sx;
02394                                                 if ( xidx >= nx) break;
02395 
02396                                                 float val = image->get_value_at(xidx,yidx);
02397                                                 if ( op( val,tmp) ) tmp = val;
02398                                         }
02399                                 }
02400                                 return_image->set_value_at(x,y,tmp);
02401                         }
02402                 }
02403         }
02404         else
02405         {
02406                 int tz = nz/shrinkz;
02407                 int ty = ny/shrinky;
02408                 int tx = nx/shrinkx;
02409 
02410                 return_image->set_size(tx,ty,tz);
02411                 for(int z = 0; z < tz; ++z) {
02412                         for(int y = 0; y < ty; ++y) {
02413                                 for(int x = 0; x < tx; ++x) {
02414                                         float tmp = op.get_start_val();
02415 
02416                                         for(int sz=0; sz < searchz; ++sz) {
02417                                                 int zidx = shrinkz*z+sz;
02418                                                 if ( zidx >= nz) break;
02419 
02420                                                 for(int sy=0; sy < searchy; ++sy) {
02421                                                         int yidx = shrinky*y+sy;
02422                                                         if ( yidx >= ny) break;
02423 
02424                                                         for(int sx=0; sx < searchx; ++sx) {
02425                                                                 int xidx = shrinkx*x+sx;
02426                                                                 if ( xidx >= nx) break;
02427                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02428                                                                 if ( op( val,tmp) ) tmp = val;
02429                                                         }
02430                                                 }
02431                                         }
02432                                         return_image->set_value_at(x,y,z,tmp);
02433                                 }
02434                         }
02435                 }
02436         }
02437         return_image->update();
02438 
02439         return return_image;
02440 }

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

02444 {
02445         // The basic idea of this code is to iterate through each pixel in the output image
02446         // determining its value by investigation a region of the input image
02447         if (!image) throw NullPointerException("Attempt to max shrink a null image");
02448 
02449         if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
02450 
02451 
02452         int shrink = params.set_default("shrink",2);
02453         int search = params.set_default("search",2);
02454 
02455         if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
02456 
02457 
02458         int nz = image->get_zsize();
02459         int ny = image->get_ysize();
02460         int nx = image->get_xsize();
02461 
02462         LogicOp op;
02463 
02464         int shrinkx = shrink;
02465         int shrinky = shrink;
02466         int shrinkz = shrink;
02467 
02468         int searchx = search;
02469         int searchy = search;
02470         int searchz = search;
02471 
02472         // Clamping the shrink values to the dimension lengths
02473         // ensures that the return image has non zero dimensions
02474         if ( shrinkx > nx ) shrinkx = nx;
02475         if ( shrinky > ny ) shrinkx = ny;
02476         if ( shrinkz > nz ) shrinkx = nz;
02477 
02478         if (nx == 1 && ny == 1 && nz == 1 ) return;
02479 
02480         if ( nz == 1 && ny == 1 )
02481         {
02482                 for(int i = 0; i < nx/shrink; ++i)
02483                 {
02484                         float tmp = op.get_start_val();
02485                         for(int s=0; s < searchx; ++s)
02486                         {
02487                                 int idx = shrinkx*i+s;
02488                                 if ( idx > nx ) break;
02489                                 else
02490                                 {
02491                                         float val = image->get_value_at(idx);
02492                                         if ( op( val,tmp) ) tmp = val;
02493                                 }
02494                         }
02495                         image->set_value_at(i,tmp);
02496                 }
02497 
02498                 image->set_size(nx/shrinkx);
02499         }
02500         else if ( nz == 1 )
02501         {
02502                 int ty = ny/shrinky;
02503                 int tx = nx/shrinkx;
02504                 for(int y = 0; y < ty; ++y) {
02505                         for(int x = 0; x < tx; ++x) {
02506                                 float tmp = op.get_start_val();
02507                                 for(int sy=0; sy < searchy; ++sy) {
02508                                         int yidx = shrinky*y+sy;
02509                                         if ( yidx >= ny) break;
02510                                         for(int sx=0; sx < searchx; ++sx) {
02511                                                 int xidx = shrinkx*x+sx;
02512                                                 if ( xidx >= nx) break;
02513 
02514                                                 float val = image->get_value_at(xidx,yidx);
02515                                                 if ( op( val,tmp) ) tmp = val;
02516                                         }
02517                                 }
02518                                 (*image)(x+tx*y) = tmp;
02519                         }
02520                 }
02521                 image->set_size(tx,ty);
02522         }
02523         else
02524         {
02525                 int tnxy = nx/shrinkx*ny/shrinky;
02526                 int tz = nz/shrinkz;
02527                 int ty = ny/shrinky;
02528                 int tx = nx/shrinkx;
02529 
02530                 for(int z = 0; z < tz; ++z) {
02531                         for(int y = 0; y < ty; ++y) {
02532                                 for(int x = 0; x < tx; ++x) {
02533                                         float tmp = op.get_start_val();
02534                                         for(int sz=0; sz < searchz; ++sz) {
02535                                                 int zidx = shrinkz*z+sz;
02536                                                 if ( zidx >= nz) break;
02537                                                 for(int sy=0; sy < searchy; ++sy) {
02538                                                         int yidx = shrinky*y+sy;
02539                                                         if ( yidx >= ny) break;
02540                                                         for(int sx=0; sx < shrinkx; ++sx) {
02541                                                                 int xidx = shrinkx*x+sx;
02542                                                                 if ( xidx >= nx) break;
02543 
02544                                                                 float val = image->get_value_at(xidx,yidx,zidx);
02545                                                                 if ( op( val,tmp) ) tmp = val;
02546                                                         }
02547                                                 }
02548                                         }
02549                                         (*image)(x+tx*y+tnxy*z) = tmp;
02550                                 }
02551                         }
02552                 }
02553                 image->set_size(tx,ty,tz);
02554         }
02555         image->update();
02556 }


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:46:10 2011 for EMAN2 by  doxygen 1.3.9.1