EMAN2
Protected Member Functions | List of all 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]

Protected Member Functions

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

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 4844 of file processor.h.

Member Function Documentation

◆ process()

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

Boolean shrink an image, returning the processed image.

Parameters
imagethe image to operate on
paramsparameter dictionary
Exceptions
ImageFormatExceptionif the image is complex
NullPointerExceptionif the image pointer is null
Returns
the image that results from the operation

Definition at line 3344 of file processor.cpp.

3345{
3346 // The basic idea of this code is to iterate through each pixel in the output image
3347 // determining its value by investigation a region of the input image
3348
3349 if (!image) throw NullPointerException("Attempt to max shrink a null image");
3350
3351 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
3352
3353
3354 int shrink = params.set_default("n",2);
3355 int search = params.set_default("search",2);
3356
3357 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
3358
3359
3360 int nz = image->get_zsize();
3361 int ny = image->get_ysize();
3362 int nx = image->get_xsize();
3363
3364 if (nx == 1 && ny == 1 && nz == 1 ) return image->copy();
3365
3366 LogicOp op;
3367 EMData* return_image = new EMData();
3368
3369 int shrinkx = shrink;
3370 int shrinky = shrink;
3371 int shrinkz = shrink;
3372
3373 int searchx = search;
3374 int searchy = search;
3375 int searchz = search;
3376
3377 // Clamping the shrink values to the dimension lengths
3378 // ensures that the return image has non zero dimensions
3379 if ( shrinkx > nx ) shrinkx = nx;
3380 if ( shrinky > ny ) shrinky = ny;
3381 if ( shrinkz > nz ) shrinkz = nz;
3382
3383 if ( nz == 1 && ny == 1 )
3384 {
3385 return_image->set_size(nx/shrinkx);
3386 for(int i = 0; i < nx/shrinkx; ++i)
3387 {
3388 float tmp = op.get_start_val();
3389 for(int s=0; s < searchx; ++s)
3390 {
3391 int idx = shrinkx*i+s;
3392 // Don't ask for memory beyond limits
3393 if ( idx > nx ) break;
3394 else
3395 {
3396 float val = image->get_value_at(idx);
3397 if ( op( val,tmp) ) tmp = val;
3398 }
3399 }
3400 return_image->set_value_at(i,tmp);
3401 }
3402 }
3403 else if ( nz == 1 )
3404 {
3405 int ty = ny/shrinky;
3406 int tx = nx/shrinkx;
3407 return_image->set_size(tx,ty);
3408 for(int y = 0; y < ty; ++y) {
3409 for(int x = 0; x < tx; ++x) {
3410 float tmp = op.get_start_val();
3411 for(int sy=0; sy < searchy; ++sy) {
3412 int yidx = shrinky*y+sy;
3413 if ( yidx >= ny) break;
3414 for(int sx=0; sx < searchx; ++sx) {
3415 int xidx = shrinkx*x+sx;
3416 if ( xidx >= nx) break;
3417
3418 float val = image->get_value_at(xidx,yidx);
3419 if ( op( val,tmp) ) tmp = val;
3420 }
3421 }
3422 return_image->set_value_at(x,y,tmp);
3423 }
3424 }
3425 }
3426 else
3427 {
3428 int tz = nz/shrinkz;
3429 int ty = ny/shrinky;
3430 int tx = nx/shrinkx;
3431
3432 return_image->set_size(tx,ty,tz);
3433 for(int z = 0; z < tz; ++z) {
3434 for(int y = 0; y < ty; ++y) {
3435 for(int x = 0; x < tx; ++x) {
3436 float tmp = op.get_start_val();
3437
3438 for(int sz=0; sz < searchz; ++sz) {
3439 int zidx = shrinkz*z+sz;
3440 if ( zidx >= nz) break;
3441
3442 for(int sy=0; sy < searchy; ++sy) {
3443 int yidx = shrinky*y+sy;
3444 if ( yidx >= ny) break;
3445
3446 for(int sx=0; sx < searchx; ++sx) {
3447 int xidx = shrinkx*x+sx;
3448 if ( xidx >= nx) break;
3449 float val = image->get_value_at(xidx,yidx,zidx);
3450 if ( op( val,tmp) ) tmp = val;
3451 }
3452 }
3453 }
3454 return_image->set_value_at(x,y,z,tmp);
3455 }
3456 }
3457 }
3458 }
3459 return_image->update();
3460
3461 return return_image;
3462}
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ImageFormatException(desc)
Definition: exception.h:147
#define NullPointerException(desc)
Definition: exception.h:241
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References ImageFormatException, InvalidValueException, NullPointerException, EMAN::Dict::set_default(), x, and y.

◆ process_inplace()

template<class LogicOp >
void BooleanShrinkProcessor::process_inplace ( EMData image,
Dict params 
)
protected

Boolean shrink an image inplace.

Parameters
imagethe image to operate on
paramsparameter dictionary
Exceptions
ImageFormatExceptionif the image is complex
NullPointerExceptionif the image pointer is null

Definition at line 3465 of file processor.cpp.

3466{
3467 // The basic idea of this code is to iterate through each pixel in the output image
3468 // determining its value by investigation a region of the input image
3469 if (!image) throw NullPointerException("Attempt to max shrink a null image");
3470
3471 if (image->is_complex() ) throw ImageFormatException("Can not max shrink a complex image");
3472
3473
3474 int shrink = params.set_default("shrink",2);
3475 int search = params.set_default("search",2);
3476
3477 if ( shrink < 0 ) throw InvalidValueException(shrink, "Can not shrink by a value less than 0");
3478
3479
3480 int nz = image->get_zsize();
3481 int ny = image->get_ysize();
3482 int nx = image->get_xsize();
3483
3484 LogicOp op;
3485
3486 int shrinkx = shrink;
3487 int shrinky = shrink;
3488 int shrinkz = shrink;
3489
3490 int searchx = search;
3491 int searchy = search;
3492 int searchz = search;
3493
3494 // Clamping the shrink values to the dimension lengths
3495 // ensures that the return image has non zero dimensions
3496 if ( shrinkx > nx ) shrinkx = nx;
3497 if ( shrinky > ny ) shrinky = ny;
3498 if ( shrinkz > nz ) shrinkz = nz;
3499
3500 if (nx == 1 && ny == 1 && nz == 1 ) return;
3501
3502 if ( nz == 1 && ny == 1 )
3503 {
3504 for(int i = 0; i < nx/shrink; ++i)
3505 {
3506 float tmp = op.get_start_val();
3507 for(int s=0; s < searchx; ++s)
3508 {
3509 int idx = shrinkx*i+s;
3510 if ( idx > nx ) break;
3511 else
3512 {
3513 float val = image->get_value_at(idx);
3514 if ( op( val,tmp) ) tmp = val;
3515 }
3516 }
3517 image->set_value_at(i,tmp);
3518 }
3519
3520 image->set_size(nx/shrinkx);
3521 }
3522 else if ( nz == 1 )
3523 {
3524 int ty = ny/shrinky;
3525 int tx = nx/shrinkx;
3526 for(int y = 0; y < ty; ++y) {
3527 for(int x = 0; x < tx; ++x) {
3528 float tmp = op.get_start_val();
3529 for(int sy=0; sy < searchy; ++sy) {
3530 int yidx = shrinky*y+sy;
3531 if ( yidx >= ny) break;
3532 for(int sx=0; sx < searchx; ++sx) {
3533 int xidx = shrinkx*x+sx;
3534 if ( xidx >= nx) break;
3535
3536 float val = image->get_value_at(xidx,yidx);
3537 if ( op( val,tmp) ) tmp = val;
3538 }
3539 }
3540 (*image)(x+tx*y) = tmp;
3541 }
3542 }
3543 image->set_size(tx,ty);
3544 }
3545 else
3546 {
3547 int tnxy = nx/shrinkx*ny/shrinky;
3548 int tz = nz/shrinkz;
3549 int ty = ny/shrinky;
3550 int tx = nx/shrinkx;
3551
3552 for(int z = 0; z < tz; ++z) {
3553 for(int y = 0; y < ty; ++y) {
3554 for(int x = 0; x < tx; ++x) {
3555 float tmp = op.get_start_val();
3556 for(int sz=0; sz < searchz; ++sz) {
3557 int zidx = shrinkz*z+sz;
3558 if ( zidx >= nz) break;
3559 for(int sy=0; sy < searchy; ++sy) {
3560 int yidx = shrinky*y+sy;
3561 if ( yidx >= ny) break;
3562 for(int sx=0; sx < shrinkx; ++sx) {
3563 int xidx = shrinkx*x+sx;
3564 if ( xidx >= nx) break;
3565
3566 float val = image->get_value_at(xidx,yidx,zidx);
3567 if ( op( val,tmp) ) tmp = val;
3568 }
3569 }
3570 }
3571 (*image)(x+tx*y+tnxy*z) = tmp;
3572 }
3573 }
3574 }
3575 image->set_size(tx,ty,tz);
3576 }
3577 image->update();
3578}

References ImageFormatException, InvalidValueException, NullPointerException, EMAN::Dict::set_default(), x, and y.


The documentation for this class was generated from the following files: