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 3163 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 2328 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.

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

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

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


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:10:02 2011 for EMAN2 by  doxygen 1.4.7