#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 3955 of file processor.h.
float NormalizeMaskProcessor::calc_mean | ( | EMData * | image | ) | const [protected, virtual] |
Implements EMAN::NormalizeProcessor.
Definition at line 3427 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.
03428 { 03429 if (!image) { 03430 LOGWARN("NULL Image"); 03431 return 0; 03432 } 03433 EMData *mask = params["mask"]; 03434 03435 if (!EMUtil::is_same_size(mask, image)) { 03436 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03437 throw ImageDimensionException("mask and image must be the same size"); 03438 } 03439 03440 float *data = image->get_data(); 03441 float *mask_data = mask->get_data(); 03442 size_t size = image->get_xsize() * image->get_ysize() * image->get_zsize(); 03443 double sum = 0; 03444 size_t n_norm = 0; 03445 03446 for (size_t i = 0; i < size; i++) { 03447 if (mask_data[i] > 0.5f) { 03448 sum += data[i]; 03449 n_norm++; 03450 } 03451 } 03452 03453 float mean = 0; 03454 if (n_norm == 0) { 03455 mean = image->get_edge_mean(); 03456 } 03457 else { 03458 mean = (float) sum / n_norm; 03459 } 03460 03461 return mean; 03462 }
float NormalizeMaskProcessor::calc_sigma | ( | EMData * | image | ) | const [protected, virtual] |
Reimplemented from EMAN::NormalizeProcessor.
Definition at line 3391 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().
03392 { 03393 if (!image) { 03394 LOGWARN("NULL Image"); 03395 return 0; 03396 } 03397 EMData *mask = params["mask"]; 03398 int no_sigma = params["no_sigma"]; 03399 03400 if(no_sigma == 0) { 03401 return 1; 03402 } 03403 else { 03404 if (!EMUtil::is_same_size(mask, image)) { 03405 LOGERR("normalize.maskProcessor: mask and image must be the same size"); 03406 throw ImageDimensionException("mask and image must be the same size"); 03407 } 03408 03409 float *data = image->get_data(); 03410 float *mask_data = mask->get_data(); 03411 size_t size = image->get_xsize() * image->get_ysize() * image->get_zsize(); 03412 double sum = 0; 03413 double sq2 = 0; 03414 size_t n_norm = 0; 03415 03416 for (size_t i = 0; i < size; i++) { 03417 if (mask_data[i] > 0.5f) { 03418 sum += data[i]; 03419 sq2 += data[i]*double (data[i]); 03420 n_norm++; 03421 } 03422 } 03423 return sqrt(static_cast<float>((sq2 - sum * sum /n_norm)/(n_norm -1))) ; 03424 } 03425 }
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 3963 of file processor.h.
03964 { 03965 return "Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified."; 03966 }
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 3958 of file processor.h.
References NAME.
03959 { 03960 return NAME; 03961 }
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 3973 of file processor.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
03974 { 03975 TypeDict d; 03976 d.put("mask", EMObject::EMDATA, "the 1/0 mask defining a region to use for the zero-normalization"); 03977 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"); 03978 return d; 03979 }
static Processor* EMAN::NormalizeMaskProcessor::NEW | ( | ) | [inline, static] |
Definition at line 3968 of file processor.h.
03969 { 03970 return new NormalizeMaskProcessor(); 03971 }
const string NormalizeMaskProcessor::NAME = "normalize.mask" [static] |