#include <processor.h>
Inheritance diagram for EMAN::NormalizeMaskProcessor:
Public Member Functions | |
string | get_name () const |
Get the processor's name. | |
string | get_desc () const |
Get the descrition of this specific processor. | |
TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "normalize.mask" |
Protected Member Functions | |
float | calc_sigma (EMData *image) const |
float | calc_mean (EMData *image) const |
mask | the 1/0 mask defining a region to use for the zero-normalization | |
no_sigma | if this flag is zero, only average under the mask will be substracted. set this flag to 1, standard deviation not modified |
Definition at line 4165 of file processor.h.
float NormalizeMaskProcessor::calc_mean | ( | EMData * | image | ) | const [protected, virtual] |
Implements EMAN::NormalizeProcessor.
Definition at line 3565 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_edge_mean(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, EMAN::EMUtil::is_same_size(), LOGERR, LOGWARN, mean(), and EMAN::Processor::params.
03566 { 03567 if (!image) { 03568 LOGWARN("NULL Image"); 03569 return 0; 03570 } 03571 EMData *mask = params["mask"]; 03572 03573 if (!EMUtil::is_same_size(mask, image)) { 03574 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03575 throw ImageDimensionException("mask and image must be the same size"); 03576 } 03577 03578 float *data = image->get_data(); 03579 float *mask_data = mask->get_data(); 03580 size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize(); 03581 double sum = 0; 03582 size_t n_norm = 0; 03583 03584 for (size_t i = 0; i < size; ++i) { 03585 if (mask_data[i] > 0.5f) { 03586 sum += data[i]; 03587 n_norm++; 03588 } 03589 } 03590 03591 float mean = 0; 03592 if (n_norm == 0) { 03593 mean = image->get_edge_mean(); 03594 } 03595 else { 03596 mean = (float) sum / n_norm; 03597 } 03598 03599 return mean; 03600 }
float NormalizeMaskProcessor::calc_sigma | ( | EMData * | image | ) | const [protected, virtual] |
Reimplemented from EMAN::NormalizeProcessor.
Definition at line 3529 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, EMAN::EMUtil::is_same_size(), LOGERR, LOGWARN, EMAN::Processor::params, and sqrt().
03530 { 03531 if (!image) { 03532 LOGWARN("NULL Image"); 03533 return 0; 03534 } 03535 EMData *mask = params["mask"]; 03536 int no_sigma = params["no_sigma"]; 03537 03538 if(no_sigma == 0) { 03539 return 1; 03540 } 03541 else { 03542 if (!EMUtil::is_same_size(mask, image)) { 03543 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03544 throw ImageDimensionException("mask and image must be the same size"); 03545 } 03546 03547 float *data = image->get_data(); 03548 float *mask_data = mask->get_data(); 03549 size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize(); 03550 double sum = 0; 03551 double sq2 = 0; 03552 size_t n_norm = 0; 03553 03554 for (size_t i = 0; i < size; ++i) { 03555 if (mask_data[i] > 0.5f) { 03556 sum += data[i]; 03557 sq2 += data[i]*double (data[i]); 03558 n_norm++; 03559 } 03560 } 03561 return sqrt(static_cast<float>((sq2 - sum * sum /n_norm)/(n_norm -1))) ; 03562 } 03563 }
string EMAN::NormalizeMaskProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 4173 of file processor.h.
04174 { 04175 return "Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified."; 04176 }
string EMAN::NormalizeMaskProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4168 of file processor.h.
References NAME.
04169 { 04170 return NAME; 04171 }
TypeDict EMAN::NormalizeMaskProcessor::get_param_types | ( | ) | const [inline, virtual] |
Get processor parameter information in a dictionary.
Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Reimplemented from EMAN::Processor.
Definition at line 4183 of file processor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
04184 { 04185 TypeDict d; 04186 d.put("mask", EMObject::EMDATA, "the 1/0 mask defining a region to use for the zero-normalization"); 04187 d.put("no_sigma", EMObject::INT, "if this flag is zero, only average under the mask will be substracted. set this flag to 1, standard deviation not modified"); 04188 return d; 04189 }
static Processor* EMAN::NormalizeMaskProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4178 of file processor.h.
04179 { 04180 return new NormalizeMaskProcessor(); 04181 }
const string NormalizeMaskProcessor::NAME = "normalize.mask" [static] |