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:
to reference image normalize to
low_threshold only take into account the reference image's pixel value between high and low threshold (zero is ignored)
high_threshold only take into account the reference image's pixel value between high and low threshold (zero is ignored)

Definition at line 4333 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 4358 of file processor.h.

04359                 {
04360                         return "use least square method to normalize";
04361                 }

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

References NAME.

04339                 {
04340                         return NAME;
04341                 }

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

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

04349                 {
04350                         TypeDict d;
04351                         d.put("to", EMObject::EMDATA, "reference image normalize to");
04352                         d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
04353                         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)");
04354                         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)");
04355                         return d;
04356                 }

static Processor* EMAN::NormalizeToLeastSquareProcessor::NEW (  )  [inline, static]

Definition at line 4343 of file processor.h.

04344                 {
04345                         return new NormalizeToLeastSquareProcessor();
04346                 }

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:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 3742 of file processor.cpp.

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

03743 {
03744         if (!image) {
03745                 LOGWARN("NULL Image");
03746                 return;
03747         }
03748 
03749         EMData *to = params["to"];
03750 
03751         bool ignore_zero = params.set_default("ignore_zero",true);
03752 
03753         float low_threshold = FLT_MIN;
03754         string low_thr_name = "low_threshold";
03755         if (params.has_key(low_thr_name)) {
03756                 low_threshold = params[low_thr_name];
03757         }
03758 
03759         float high_threshold = FLT_MAX;
03760         string high_thr_name = "high_threshold";
03761         if (params.has_key(high_thr_name)) {
03762                 high_threshold = params[high_thr_name];
03763         }
03764 
03765         float *rawp = image->get_data();
03766         float *refp = to->get_data();
03767 
03768         int nx = image->get_xsize();
03769         int ny = image->get_ysize();
03770         int nz = image->get_zsize();
03771         size_t size = (size_t)nx * ny * nz;
03772 
03773         float sum_x = 0;
03774         float sum_y = 0;
03775         size_t count = 0;
03776 
03777         float sum_x_mean = 0;
03778         float sum_tt = 0;
03779         float b = 0;
03780 
03781         // This is really inefficient, who coded it ?   --steve
03782         if (ignore_zero) {
03783                 for (size_t i = 0; i < size; ++i) {
03784                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) {
03785                                 count++;
03786                                 sum_x += refp[i];
03787                                 sum_y += rawp[i];
03788                         }
03789                 }
03790 
03791                 sum_x_mean = sum_x / count;
03792                 sum_tt = 0;
03793                 b = 0;
03794 
03795                 float t;
03796                 for (size_t i = 0; i < size; ++i) {
03797                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) {
03798                                 t = refp[i] - sum_x_mean;
03799                                 sum_tt += t * t;
03800                                 b += t * rawp[i];
03801                         }
03802                 }
03803         }
03804         else {
03805                         for (size_t i = 0; i < size; ++i) {
03806                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03807                                 count++;
03808                                 sum_x += refp[i];
03809                                 sum_y += rawp[i];
03810                         }
03811                 }
03812 
03813                 sum_x_mean = sum_x / count;
03814                 sum_tt = 0;
03815                 b = 0;
03816 
03817                 float t;
03818                 for (size_t i = 0; i < size; ++i) {
03819                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03820                                 t = refp[i] - sum_x_mean;
03821                                 sum_tt += t * t;
03822                                 b += t * rawp[i];
03823                         }
03824                 }
03825         }
03826 
03827         b /= sum_tt;
03828 
03829         float a = (sum_y - sum_x * b) / count;
03830         float scale = 1 / b;
03831         float shift = -a / b;
03832 
03833         for (size_t i = 0; i < size; ++i) {
03834                 rawp[i] = (rawp[i] - a) / b;
03835         }
03836 
03837         image->update();
03838 
03839         params["scale"] = scale;
03840         params["shift"] = shift;
03841 
03842         image->set_attr("norm_mult",scale);
03843         image->set_attr("norm_add",shift);
03844 
03845 }


Member Data Documentation

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

Definition at line 4363 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:40 2011 for EMAN2 by  doxygen 1.4.7