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

04397                 {
04398                         return "use least square method to normalize";
04399                 }

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

04377                 {
04378                         return NAME;
04379                 }

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

References EMAN::TypeDict::put().

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

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

Definition at line 4381 of file processor.h.

04382                 {
04383                         return new NormalizeToLeastSquareProcessor();
04384                 }

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

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


Member Data Documentation

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

Definition at line 159 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:52:20 2011 for EMAN2 by  doxygen 1.3.9.1