EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
EMAN::MeanShrinkProcessor Class Reference

MeanShrinkProcessor shrinks an image by in an integer amount (and optionally by 1.5) taking the mean of the pixel neighbourhood. More...

#include <processor.h>

Inheritance diagram for EMAN::MeanShrinkProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::MeanShrinkProcessor:
Collaboration graph
[legend]

Public Member Functions

virtual EMDataprocess (const EMData *const image)
 The meanshrink processor has its own process function to minise memory usage - if this function was not over written the base Processor class would create copy of the input image and hand it to the process_inplace function. More...
 
virtual void process_inplace (EMData *image)
 Mean shrink inplace. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "math.meanshrink"
 

Private Member Functions

void accrue_mean (EMData *to, const EMData *const from, const int shrinkfactor)
 Accrue the local mean in the image 'from' to the image 'to' using the given shrinkfactor An internal function that encapsulates a routine common to both process and process inplace. More...
 
void accrue_mean_one_p_five (EMData *to, const EMData *const from)
 Accrue the local mean in the image 'from' to the image 'to' using the the special case shrink factor of 1.5 This is an internal function that encapsulates a routine common to both process and process inplace. More...
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

MeanShrinkProcessor shrinks an image by in an integer amount (and optionally by 1.5) taking the mean of the pixel neighbourhood.

Author
David Woolford (But is basically a copy of the old EMData::mean_shrink, probably written by Steven Ludtke )
Date
May 2008
Parameters
nThe shrink factor

Definition at line 4993 of file processor.h.

Member Function Documentation

◆ accrue_mean()

void MeanShrinkProcessor::accrue_mean ( EMData to,
const EMData *const  from,
const int  shrinkfactor 
)
private

Accrue the local mean in the image 'from' to the image 'to' using the given shrinkfactor An internal function that encapsulates a routine common to both process and process inplace.

Parameters
tothe smaller image that will store the mean values
fromthe larger image that will be used to calculate the mean values
shrinkfactorthe shrink amount

Definition at line 3229 of file processor.cpp.

3230{
3231 const float * const data = from->get_const_data();
3232 float* rdata = to->get_data();
3233
3234 size_t nx = from->get_xsize();
3235 size_t ny = from->get_ysize();
3236 size_t nz = from->get_zsize();
3237 size_t nxy = nx*ny;
3238
3239
3240 size_t shrunken_nx = nx / shrink_factor;
3241 size_t shrunken_ny = ny / shrink_factor;
3242 size_t shrunken_nz = 1;
3243 size_t shrunken_nxy = shrunken_nx * shrunken_ny;
3244
3245 int normalize_shrink_factor = shrink_factor * shrink_factor;
3246 int z_shrink_factor = 1;
3247
3248 if (nz > 1) {
3249 shrunken_nz = nz / shrink_factor;
3250 normalize_shrink_factor *= shrink_factor;
3251 z_shrink_factor = shrink_factor;
3252 }
3253
3254 float invnormfactor = 1.0f/(float)normalize_shrink_factor;
3255
3256 for (size_t k = 0; k < shrunken_nz; k++) {
3257 size_t k_min = k * shrink_factor;
3258 size_t k_max = k * shrink_factor + z_shrink_factor;
3259 size_t cur_k = k * shrunken_nxy;
3260
3261 for (size_t j = 0; j < shrunken_ny; j++) {
3262 size_t j_min = j * shrink_factor;
3263 size_t j_max = j * shrink_factor + shrink_factor;
3264 size_t cur_j = j * shrunken_nx + cur_k;
3265
3266 for (size_t i = 0; i < shrunken_nx; i++) {
3267 size_t i_min = i * shrink_factor;
3268 size_t i_max = i * shrink_factor + shrink_factor;
3269
3270 float sum = 0;
3271 for (size_t kk = k_min; kk < k_max; kk++) {
3272 size_t cur_kk = kk * nxy;
3273
3274 for (size_t jj = j_min; jj < j_max; jj++) {
3275 size_t cur_jj = jj * nx + cur_kk;
3276 for (size_t ii = i_min; ii < i_max; ii++) {
3277 sum += data[ii + cur_jj];
3278 }
3279 }
3280 }
3281 rdata[i + cur_j] = sum * invnormfactor;
3282 }
3283 }
3284 }
3285 to->scale_pixel((float)shrink_factor);
3286}
#define rdata(i)
Definition: analyzer.cpp:592

References rdata.

Referenced by process(), and process_inplace().

◆ accrue_mean_one_p_five()

void MeanShrinkProcessor::accrue_mean_one_p_five ( EMData to,
const EMData *const  from 
)
private

Accrue the local mean in the image 'from' to the image 'to' using the the special case shrink factor of 1.5 This is an internal function that encapsulates a routine common to both process and process inplace.

Parameters
tothe smaller image that will store the mean values
fromthe larger image that will be used to calculate the mean values

Definition at line 3289 of file processor.cpp.

3290{
3291 int nx0 = from->get_xsize(), ny0 = from->get_ysize(); // the original size
3292
3293 int nx = to->get_xsize(), ny = to->get_ysize();
3294
3295 float *data = to->get_data();
3296 const float * const data0 = from->get_const_data();
3297
3298 for (int j = 0; j < ny; j++) {
3299 int jj = int(j * 1.5);
3300 float jw0 = 1.0F, jw1 = 0.5F; // 3x3 -> 2x2, so each new pixel should have 2.25 of the old pixels
3301 if ( j%2 ) {
3302 jw0 = 0.5F;
3303 jw1 = 1.0F;
3304 }
3305 for (int i = 0; i < nx; i++) {
3306 int ii = int(i * 1.5);
3307 float iw0 = 1.0F, iw1 = 0.5F;
3308 float w = 0.0F;
3309
3310 if ( i%2 ) {
3311 iw0 = 0.5F;
3312 iw1 = 1.0F;
3313 }
3314 if ( jj < ny0 ) {
3315 if ( ii < nx0 ) {
3316 data[j * nx + i] = data0[ jj * nx0 + ii ] * jw0 * iw0 ;
3317 w += jw0 * iw0 ;
3318 if ( ii+1 < nx0 ) {
3319 data[j * nx + i] += data0[ jj * nx0 + ii + 1] * jw0 * iw1;
3320 w += jw0 * iw1;
3321 }
3322 }
3323 if ( jj +1 < ny0 ) {
3324 if ( ii < nx0 ) {
3325 data[j * nx + i] += data0[ (jj+1) * nx0 + ii ] * jw1 * iw0;
3326 w += jw1 * iw0;
3327 if ( ii+1 < nx0 ) {
3328 data[j * nx + i] += data0[ (jj+1) * nx0 + ii + 1] * jw1 * iw1;
3329 w += jw1 * iw1;
3330 }
3331 }
3332 }
3333 }
3334 if ( w>0 ) data[j * nx + i] /= w;
3335 }
3336 }
3337
3338 to->update();
3339 to->scale_pixel((float)1.5);
3340}

Referenced by process(), and process_inplace().

◆ get_desc()

string EMAN::MeanShrinkProcessor::get_desc ( ) const
inlinevirtual

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns
The description of this processor.

Implements EMAN::Processor.

Definition at line 5016 of file processor.h.

5017 {
5018 return "Shrink an image by a given amount , using the mean value found in the pixel neighborhood.";
5019 }

◆ get_name()

virtual string EMAN::MeanShrinkProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 5021 of file processor.h.

5022 {
5023 return NAME;
5024 }
static const string NAME
Definition: processor.h:5037

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::MeanShrinkProcessor::get_param_types ( ) const
inlinevirtual

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 5030 of file processor.h.

5031 {
5032 TypeDict d;
5033 d.put("n", EMObject::FLOAT, "The shrink factor");
5034 return d;
5035 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().

◆ NEW()

static Processor * EMAN::MeanShrinkProcessor::NEW ( )
inlinestatic

Definition at line 5025 of file processor.h.

5026 {
5027 return new MeanShrinkProcessor();
5028 }
MeanShrinkProcessor shrinks an image by in an integer amount (and optionally by 1....
Definition: processor.h:4994

◆ process()

EMData * MeanShrinkProcessor::process ( const EMData *const  image)
virtual

The meanshrink processor has its own process function to minise memory usage - if this function was not over written the base Processor class would create copy of the input image and hand it to the process_inplace function.

This latter approach mallocs and copies more memory than necessary

Parameters
imagethe image that will be used to generate a 'mean shrunken' image
Exceptions
ImageFormatExceptionif the image is complex
ImageDimensionExceptionif the image is 1D
InvalidValueExceptionif the shrink amount is a nonzero integer, unless it is 1.5, which is an exceptional circumstance

Reimplemented from EMAN::Processor.

Definition at line 3124 of file processor.cpp.

3125{
3126 if (image->is_complex()) throw ImageFormatException("Error, the mean shrink processor does not work on complex images");
3127
3128 if (image->get_ndim() == 1) { throw ImageDimensionException("Error, mean shrink works only for 2D & 3D images"); }
3129
3130 float shrink_factor0 = params.set_default("n",0.0f);
3131 int shrink_factor = int(shrink_factor0);
3132 if (shrink_factor0 <= 1.0F || ((shrink_factor0 != shrink_factor) && (shrink_factor0 != 1.5F) ) ) {
3133 throw InvalidValueException(shrink_factor0,
3134 "mean shrink: shrink factor must be >1 integer or 1.5");
3135 }
3136
3137 int nx = image->get_xsize();
3138 int ny = image->get_ysize();
3139 int nz = image->get_zsize();
3140
3141
3142 // here handle the special averaging by 1.5 for 2D case
3143 if (shrink_factor0==1.5 ) {
3144 if (nz > 1 ) throw InvalidValueException(shrink_factor0, "mean shrink: only support 2D images for shrink factor = 1.5");
3145
3146 int shrunken_nx = (int(nx / 1.5)+1)/2*2; // make sure the output size is even
3147 int shrunken_ny = (int(ny / 1.5)+1)/2*2;
3148 EMData* result = new EMData(shrunken_nx,shrunken_ny,1);
3149
3150 accrue_mean_one_p_five(result,image);
3151 result->update();
3152
3153 return result;
3154 }
3155
3156 int shrunken_nx = nx / shrink_factor;
3157 int shrunken_ny = ny / shrink_factor;
3158 int shrunken_nz = 1;
3159
3160 if (nz > 1) {
3161 shrunken_nz = nz / shrink_factor;
3162 }
3163
3164// EMData* result = new EMData(shrunken_nx,shrunken_ny,shrunken_nz);
3165 EMData* result = image->copy_head();
3166 result->set_size(shrunken_nx,shrunken_ny,shrunken_nz);
3167 accrue_mean(result,image,shrink_factor);
3168
3169 result->update();
3170
3171 return result;
3172}
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
void accrue_mean_one_p_five(EMData *to, const EMData *const from)
Accrue the local mean in the image 'from' to the image 'to' using the the special case shrink factor ...
Definition: processor.cpp:3289
void accrue_mean(EMData *to, const EMData *const from, const int shrinkfactor)
Accrue the local mean in the image 'from' to the image 'to' using the given shrinkfactor An internal ...
Definition: processor.cpp:3229
#define InvalidValueException(val, desc)
Definition: exception.h:285
#define ImageFormatException(desc)
Definition: exception.h:147
#define ImageDimensionException(desc)
Definition: exception.h:166

References accrue_mean(), accrue_mean_one_p_five(), ImageDimensionException, ImageFormatException, InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

◆ process_inplace()

void MeanShrinkProcessor::process_inplace ( EMData image)
virtual

Mean shrink inplace.

Parameters
imagethe image that will be 'mean shrunken' inplace
Exceptions
ImageFormatExceptionif the image is complex
ImageDimensionExceptionif the image is 1D
InvalidValueExceptionif the shrink amount is a nonzero integer, unless it is 1.5, which is an exceptional circumstance

Implements EMAN::Processor.

Definition at line 3174 of file processor.cpp.

3175{
3176 if (image->is_complex()) throw ImageFormatException("Error, the mean shrink processor does not work on complex images");
3177
3178 if (image->get_ndim() == 1) { throw ImageDimensionException("Error, mean shrink works only for 2D & 3D images"); }
3179
3180 float shrink_factor0 = params.set_default("n",0.0f);
3181 int shrink_factor = int(shrink_factor0);
3182 if (shrink_factor0 <= 1.0F || ((shrink_factor0 != shrink_factor) && (shrink_factor0 != 1.5F) ) ) {
3183 throw InvalidValueException(shrink_factor0,
3184 "mean shrink: shrink factor must be >1 integer or 1.5");
3185 }
3186
3187/* if ((nx % shrink_factor != 0) || (ny % shrink_factor != 0) ||
3188 (nz > 1 && (nz % shrink_factor != 0))) {
3189 throw InvalidValueException(shrink_factor,
3190 "Image size not divisible by shrink factor");
3191}*/
3192
3193 int nx = image->get_xsize();
3194 int ny = image->get_ysize();
3195 int nz = image->get_zsize();
3196 // here handle the special averaging by 1.5 for 2D case
3197 if (shrink_factor0==1.5 ) {
3198 if (nz > 1 ) throw InvalidValueException(shrink_factor0, "mean shrink: only support 2D images for shrink factor = 1.5");
3199
3200 int shrunken_nx = (int(nx / 1.5)+1)/2*2; // make sure the output size is even
3201 int shrunken_ny = (int(ny / 1.5)+1)/2*2;
3202
3203 EMData* orig = image->copy();
3204 image->set_size(shrunken_nx, shrunken_ny, 1); // now nx = shrunken_nx, ny = shrunken_ny
3205 image->to_zero();
3206
3207 accrue_mean_one_p_five(image,orig);
3208
3209 if( orig ) {
3210 delete orig;
3211 orig = 0;
3212 }
3213 image->update();
3214
3215 return;
3216 }
3217
3218 accrue_mean(image,image,shrink_factor);
3219
3220 int shrunken_nx = nx / shrink_factor;
3221 int shrunken_ny = ny / shrink_factor;
3222 int shrunken_nz = 1;
3223 if (nz > 1) shrunken_nz = nz / shrink_factor;
3224
3225 image->update();
3226 image->set_size(shrunken_nx, shrunken_ny, shrunken_nz);
3227}

References accrue_mean(), accrue_mean_one_p_five(), ImageDimensionException, ImageFormatException, InvalidValueException, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

const string MeanShrinkProcessor::NAME = "math.meanshrink"
static

Definition at line 5037 of file processor.h.

Referenced by get_name().


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