#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 4210 of file processor.h.
float NormalizeMaskProcessor::calc_mean | ( | EMData * | image | ) | const [protected, virtual] |
Implements EMAN::NormalizeProcessor.
Definition at line 3637 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.
03638 { 03639 if (!image) { 03640 LOGWARN("NULL Image"); 03641 return 0; 03642 } 03643 EMData *mask = params["mask"]; 03644 03645 if (!EMUtil::is_same_size(mask, image)) { 03646 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03647 throw ImageDimensionException("mask and image must be the same size"); 03648 } 03649 03650 float *data = image->get_data(); 03651 float *mask_data = mask->get_data(); 03652 size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize(); 03653 double sum = 0; 03654 size_t n_norm = 0; 03655 03656 for (size_t i = 0; i < size; ++i) { 03657 if (mask_data[i] > 0.5f) { 03658 sum += data[i]; 03659 n_norm++; 03660 } 03661 } 03662 03663 float mean = 0; 03664 if (n_norm == 0) { 03665 mean = image->get_edge_mean(); 03666 } 03667 else { 03668 mean = (float) sum / n_norm; 03669 } 03670 03671 return mean; 03672 }
float NormalizeMaskProcessor::calc_sigma | ( | EMData * | image | ) | const [protected, virtual] |
Reimplemented from EMAN::NormalizeProcessor.
Definition at line 3601 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().
03602 { 03603 if (!image) { 03604 LOGWARN("NULL Image"); 03605 return 0; 03606 } 03607 EMData *mask = params["mask"]; 03608 int no_sigma = params["no_sigma"]; 03609 03610 if(no_sigma == 0) { 03611 return 1; 03612 } 03613 else { 03614 if (!EMUtil::is_same_size(mask, image)) { 03615 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03616 throw ImageDimensionException("mask and image must be the same size"); 03617 } 03618 03619 float *data = image->get_data(); 03620 float *mask_data = mask->get_data(); 03621 size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize(); 03622 double sum = 0; 03623 double sq2 = 0; 03624 size_t n_norm = 0; 03625 03626 for (size_t i = 0; i < size; ++i) { 03627 if (mask_data[i] > 0.5f) { 03628 sum += data[i]; 03629 sq2 += data[i]*double (data[i]); 03630 n_norm++; 03631 } 03632 } 03633 return sqrt(static_cast<float>((sq2 - sum * sum /n_norm)/(n_norm -1))) ; 03634 } 03635 }
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 4218 of file processor.h.
04219 { 04220 return "Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified."; 04221 }
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 4213 of file processor.h.
References NAME.
04214 { 04215 return NAME; 04216 }
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 4228 of file processor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
04229 { 04230 TypeDict d; 04231 d.put("mask", EMObject::EMDATA, "the 1/0 mask defining a region to use for the zero-normalization"); 04232 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"); 04233 return d; 04234 }
static Processor* EMAN::NormalizeMaskProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4223 of file processor.h.
04224 { 04225 return new NormalizeMaskProcessor(); 04226 }
const string NormalizeMaskProcessor::NAME = "normalize.mask" [static] |