EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
EMAN::NormalizeMaskProcessor Class Reference

Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified. More...

#include <processor.h>

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

List of all members.

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 ProcessorNEW ()

Static Public Attributes

static const string NAME = "normalize.mask"

Protected Member Functions

float calc_sigma (EMData *image) const
float calc_mean (EMData *image) const

Detailed Description

Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified.

Parameters:
maskthe 1/0 mask defining a region to use for the zero-normalization
no_sigmaif this flag is zero, only average under the mask will be substracted. set this flag to 1, standard deviation not modified

Definition at line 4406 of file processor.h.


Member Function Documentation

float NormalizeMaskProcessor::calc_mean ( EMData image) const [protected, virtual]

Implements EMAN::NormalizeProcessor.

Definition at line 3705 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.

{
        if (!image) {
                LOGWARN("NULL Image");
                return 0;
        }
        EMData *mask = params["mask"];

        if (!EMUtil::is_same_size(mask, image)) {
                LOGERR("normalize.maskProcessor: mask and image must be the same size");
                throw ImageDimensionException("mask and image must be the same size");
        }

        float *data = image->get_data();
        float *mask_data = mask->get_data();
        size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize();
        double sum = 0;
        size_t n_norm = 0;

        for (size_t i = 0; i < size; ++i) {
                if (mask_data[i] > 0.5f) {
                        sum += data[i];
                        n_norm++;
                }
        }

        float mean = 0;
        if (n_norm == 0) {
                mean = image->get_edge_mean();
        }
        else {
                mean = (float) sum / n_norm;
        }

        return mean;
}
float NormalizeMaskProcessor::calc_sigma ( EMData image) const [protected, virtual]

Reimplemented from EMAN::NormalizeProcessor.

Definition at line 3669 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().

{
        if (!image) {
                LOGWARN("NULL Image");
                return 0;
        }
        EMData *mask = params["mask"];
        int no_sigma = params["no_sigma"];

        if(no_sigma == 0) {
                return 1;
        }
        else {
                if (!EMUtil::is_same_size(mask, image)) {
                        LOGERR("normalize.maskProcessor: mask and image must be the same size");
                        throw ImageDimensionException("mask and image must be the same size");
                }

                float *data = image->get_data();
                float *mask_data = mask->get_data();
                size_t size = (size_t)image->get_xsize() * image->get_ysize() * image->get_zsize();
                double sum = 0;
                double sq2 = 0;
                size_t n_norm = 0;

                for (size_t i = 0; i < size; ++i) {
                        if (mask_data[i] > 0.5f) {
                                sum += data[i];
                                sq2 += data[i]*double (data[i]);
                                n_norm++;
                        }
                }
                return sqrt(static_cast<float>((sq2 - sum * sum /n_norm)/(n_norm -1))) ;
        }
}
string EMAN::NormalizeMaskProcessor::get_desc ( ) const [inline, virtual]

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 4414 of file processor.h.

                {
                        return "Uses a 1/0 mask defining a region to use for the zero-normalization.if no_sigma is 1, standard deviation not modified.";
                }
string EMAN::NormalizeMaskProcessor::get_name ( ) const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 4409 of file processor.h.

References NAME.

                {
                        return NAME;
                }
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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 4424 of file processor.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

                {
                        TypeDict d;
                        d.put("mask", EMObject::EMDATA, "the 1/0 mask defining a region to use for the zero-normalization");
                        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");
                        return d;
                }
static Processor* EMAN::NormalizeMaskProcessor::NEW ( ) [inline, static]

Definition at line 4419 of file processor.h.

                {
                        return new NormalizeMaskProcessor();
                }

Member Data Documentation

const string NormalizeMaskProcessor::NAME = "normalize.mask" [static]

Definition at line 4432 of file processor.h.

Referenced by get_name().


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