Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

ProcessorNEW ()

Static Public Attributes

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

04303                 {
04304                         return "use least square method to normalize";
04305                 }

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

04283                 {
04284                         return NAME;
04285                 }

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

References EMAN::TypeDict::put().

04293                 {
04294                         TypeDict d;
04295                         d.put("to", EMObject::EMDATA, "reference image normalize to");
04296                         d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
04297                         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)");
04298                         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)");
04299                         return d;
04300                 }

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

Definition at line 4287 of file processor.h.

04288                 {
04289                         return new NormalizeToLeastSquareProcessor();
04290                 }

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 3711 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, nx, ny, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), t, and EMAN::EMData::update().

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


Member Data Documentation

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

Definition at line 151 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:17:45 2011 for EMAN2 by  doxygen 1.3.9.1