EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::NormalizeToLeastSquareProcessor Class Reference

use least square method to normalize More...

#include <processor.h>

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

List of all members.

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place.
string get_name () const
 Get the processor's name.
TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "normalize.toimage"

Detailed Description

use least square method to normalize

Parameters:
toreference image normalize to
low_thresholdonly take into account the reference image's pixel value between high and low threshold (zero is ignored)
high_thresholdonly take into account the reference image's pixel value between high and low threshold (zero is ignored)

Definition at line 4701 of file processor.h.


Member Function Documentation

string EMAN::NormalizeToLeastSquareProcessor::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 4727 of file processor.h.

                {
                        return "use least square method to normalize";
                }
string EMAN::NormalizeToLeastSquareProcessor::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 4706 of file processor.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::NormalizeToLeastSquareProcessor::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 4716 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("to", EMObject::EMDATA, "reference image normalize to");
                        d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
                        d.put("ignore_lowsig", EMObject::FLOAT, "If >0, then any pixels closer to the mean than val*sigma in either image excluded");
                        d.put("low_threshold", EMObject::FLOAT, "only take into account the reference image's pixel value between high and low threshold (zero is always ignored)");
                        d.put("high_threshold", EMObject::FLOAT, "only take into account the reference image's pixel value between high and low threshold (zero is always ignored)");
                        return d;
                }
static Processor* EMAN::NormalizeToLeastSquareProcessor::NEW ( ) [inline, static]

Definition at line 4711 of file processor.h.

void NormalizeToLeastSquareProcessor::process_inplace ( EMData image) [virtual]

To process an image in-place.

For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.

Parameters:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 4113 of file processor.cpp.

References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, EMAN::Processor::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), and x.

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }

        EMData *to = params["to"];

        bool ignore_zero = params.set_default("ignore_zero",true);
        float ignore_lowsig = params.set_default("ignore_lowsig",-1.0);
        float low_threshold = params.set_default("low_threshold",-FLT_MAX);
        float high_threshold = params.set_default("high_threshold",FLT_MAX);

        float *dimage = image->get_data();
        float *dto = to->get_data();

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();
        size_t size = (size_t)nx * ny * nz;

        // rewrote this to just use GSL and get rid of David's old code.
        // The two passes are just to make sure we don't eat too much RAM if we do 3D
        if (ignore_lowsig<0) ignore_lowsig=0;
//      FILE *dbug = fopen("dbug.txt","w");

        size_t count=0;
        float meani=(float)image->get_attr("mean");
        float meant=(float)to->get_attr("mean");
        float sigi=(float)image->get_attr("sigma")*ignore_lowsig;
        float sigt=(float)to->get_attr("sigma")*ignore_lowsig;
        for (size_t i = 0; i < size; ++i) {
                if (dto[i] >= low_threshold && dto[i] <= high_threshold
                        && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
                        && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
                        && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
                        count++;
//                      fprintf(dbug,"%f\t%f\n",dimage[i],dto[i]);
                }
        }
//      fclose(dbug);

        double *x=(double *)malloc(count*sizeof(double));
        double *y=(double *)malloc(count*sizeof(double));
        count=0;
        for (size_t i = 0; i < size; ++i) {
                if (dto[i] >= low_threshold && dto[i] <= high_threshold
                        && (dto[i]>=meant+sigt || dto[i]<=meant-sigt)
                        && (dimage[i]>=meani+sigi || dimage[i]<=meani-sigi)
                        && (!ignore_zero ||(dto[i] != 0.0f && dimage[i] != 0.0f))) {
                        x[count]=dimage[i];
                        y[count]=dto[i];
                        count++;
                }
        }
        double c0,c1;
        double cov00,cov01,cov11,sumsq;
        gsl_fit_linear (x, 1, y, 1, count, &c0, &c1, &cov00, &cov01, &cov11, &sumsq);

        free(x);
        free(y);

        for (size_t i = 0; i < size; ++i) dimage[i]=dimage[i]*c1+c0;
        image->set_attr("norm_mult",c1);
        image->set_attr("norm_add",c0);
        image->update();
}

Member Data Documentation

const string NormalizeToLeastSquareProcessor::NAME = "normalize.toimage" [static]

Definition at line 4732 of file processor.h.

Referenced by get_name().


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