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

04428                 {
04429                         return "use least square method to normalize";
04430                 }

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

04408                 {
04409                         return NAME;
04410                 }

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

References EMAN::TypeDict::put().

04418                 {
04419                         TypeDict d;
04420                         d.put("to", EMObject::EMDATA, "reference image normalize to");
04421                         d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True.");
04422                         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)");
04423                         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)");
04424                         return d;
04425                 }

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

Definition at line 4412 of file processor.h.

04413                 {
04414                         return new NormalizeToLeastSquareProcessor();
04415                 }

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

03786 {
03787         if (!image) {
03788                 LOGWARN("NULL Image");
03789                 return;
03790         }
03791 
03792         EMData *to = params["to"];
03793 
03794         bool ignore_zero = params.set_default("ignore_zero",true);
03795 
03796         float low_threshold = FLT_MIN;
03797         string low_thr_name = "low_threshold";
03798         if (params.has_key(low_thr_name)) {
03799                 low_threshold = params[low_thr_name];
03800         }
03801 
03802         float high_threshold = FLT_MAX;
03803         string high_thr_name = "high_threshold";
03804         if (params.has_key(high_thr_name)) {
03805                 high_threshold = params[high_thr_name];
03806         }
03807 
03808         float *rawp = image->get_data();
03809         float *refp = to->get_data();
03810 
03811         int nx = image->get_xsize();
03812         int ny = image->get_ysize();
03813         int nz = image->get_zsize();
03814         size_t size = (size_t)nx * ny * nz;
03815 
03816         float sum_x = 0;
03817         float sum_y = 0;
03818         size_t count = 0;
03819 
03820         float sum_x_mean = 0;
03821         float sum_tt = 0;
03822         float b = 0;
03823 
03824         // This is really inefficient, who coded it ?   --steve
03825         if (ignore_zero) {
03826                 for (size_t i = 0; i < size; ++i) {
03827                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) {
03828                                 count++;
03829                                 sum_x += refp[i];
03830                                 sum_y += rawp[i];
03831                         }
03832                 }
03833 
03834                 sum_x_mean = sum_x / count;
03835                 sum_tt = 0;
03836                 b = 0;
03837 
03838                 float t;
03839                 for (size_t i = 0; i < size; ++i) {
03840                         if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) {
03841                                 t = refp[i] - sum_x_mean;
03842                                 sum_tt += t * t;
03843                                 b += t * rawp[i];
03844                         }
03845                 }
03846         }
03847         else {
03848                         for (size_t i = 0; i < size; ++i) {
03849                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03850                                 count++;
03851                                 sum_x += refp[i];
03852                                 sum_y += rawp[i];
03853                         }
03854                 }
03855 
03856                 sum_x_mean = sum_x / count;
03857                 sum_tt = 0;
03858                 b = 0;
03859 
03860                 float t;
03861                 for (size_t i = 0; i < size; ++i) {
03862                         if (refp[i] >= low_threshold && refp[i] <= high_threshold) {
03863                                 t = refp[i] - sum_x_mean;
03864                                 sum_tt += t * t;
03865                                 b += t * rawp[i];
03866                         }
03867                 }
03868         }
03869 
03870         b /= sum_tt;
03871 
03872         float a = (sum_y - sum_x * b) / count;
03873         float scale = 1 / b;
03874         float shift = -a / b;
03875 
03876         for (size_t i = 0; i < size; ++i) {
03877                 rawp[i] = (rawp[i] - a) / b;
03878         }
03879 
03880         image->update();
03881 
03882         params["scale"] = scale;
03883         params["shift"] = shift;
03884 
03885         image->set_attr("norm_mult",scale);
03886         image->set_attr("norm_add",shift);
03887 
03888 }


Member Data Documentation

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

Definition at line 154 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:46:22 2011 for EMAN2 by  doxygen 1.3.9.1