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