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

04394                 {
04395                         return "use least square method to normalize";
04396                 }

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

References NAME.

04374                 {
04375                         return NAME;
04376                 }

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

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

04384                 {
04385                         TypeDict d;
04386                         d.put("to", EMObject::EMDATA, "reference image normalize to");
04387                         d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
04388                         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)");
04389                         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)");
04390                         return d;
04391                 }

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

Definition at line 4378 of file processor.h.

04379                 {
04380                         return new NormalizeToLeastSquareProcessor();
04381                 }

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 3696 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().

03697 {
03698         if (!image) {
03699                 LOGWARN("NULL Image");
03700                 return;
03701         }
03702 
03703         EMData *to = params["to"];
03704 
03705         bool ignore_zero = params.set_default("ignore_zero",true);
03706         
03707         float low_threshold = FLT_MIN;
03708         string low_thr_name = "low_threshold";
03709         if (params.has_key(low_thr_name)) {
03710                 low_threshold = params[low_thr_name];
03711         }
03712 
03713         float high_threshold = FLT_MAX;
03714         string high_thr_name = "high_threshold";
03715         if (params.has_key(high_thr_name)) {
03716                 high_threshold = params[high_thr_name];
03717         }
03718 
03719         float *rawp = image->get_data();
03720         float *refp = to->get_data();
03721 
03722         int nx = image->get_xsize();
03723         int ny = image->get_ysize();
03724         int nz = image->get_zsize();
03725         size_t size = nx * ny * nz;
03726 
03727         float sum_x = 0;
03728         float sum_y = 0;
03729         int count = 0;
03730 
03731         float sum_x_mean = 0;
03732         float sum_tt = 0;
03733         float b = 0;
03734         
03735         // This is really inefficient, who coded it ?   --steve
03736         if (ignore_zero) {
03737                 for (size_t i = 0; i < size; i++) {
03738                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) {
03739                                 count++;
03740                                 sum_x += refp[i];
03741                                 sum_y += rawp[i];
03742                         }
03743                 }
03744 
03745                 sum_x_mean = sum_x / count;
03746                 sum_tt = 0;
03747                 b = 0;
03748 
03749                 float t;
03750                 for (size_t i = 0; i < size; i++) {
03751                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) {
03752                                 t = refp[i] - sum_x_mean;
03753                                 sum_tt += t * t;
03754                                 b += t * rawp[i];
03755                         }
03756                 }
03757         }
03758         else {
03759                         for (size_t i = 0; i < size; i++) {
03760                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03761                                 count++;
03762                                 sum_x += refp[i];
03763                                 sum_y += rawp[i];
03764                         }
03765                 }
03766 
03767                 sum_x_mean = sum_x / count;
03768                 sum_tt = 0;
03769                 b = 0;
03770 
03771                 float t;
03772                 for (size_t i = 0; i < size; i++) {
03773                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03774                                 t = refp[i] - sum_x_mean;
03775                                 sum_tt += t * t;
03776                                 b += t * rawp[i];
03777                         }
03778                 }       
03779         }
03780 
03781         b /= sum_tt;
03782 
03783         float a = (sum_y - sum_x * b) / count;
03784         float scale = 1 / b;
03785         float shift = -a / b;
03786 
03787         for (size_t i = 0; i < size; i++) {
03788                 rawp[i] = (rawp[i] - a) / b;
03789         }
03790 
03791         image->update();
03792 
03793         params["scale"] = scale;
03794         params["shift"] = shift;
03795 
03796         image->set_attr("norm_mult",scale);
03797         image->set_attr("norm_add",shift);
03798 
03799 }


Member Data Documentation

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

Definition at line 4398 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:17:12 2010 for EMAN2 by  doxygen 1.4.7