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:

[legend]
Collaboration diagram for EMAN::NormalizeToLeastSquareProcessor:
[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 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 4392 of file processor.h.

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

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.

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::TypeDict::put().

04384                 {
04385                         TypeDict d;
04386                         d.put("to", EMObject::EMDATA, "reference image normalize to");
04387                         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)");
04388                         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)");
04389                         return d;
04390                 }

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

03697 {
03698         if (!image) {
03699                 LOGWARN("NULL Image");
03700                 return;
03701         }
03702 
03703         EMData *to = params["to"];
03704 
03705         float low_threshold = FLT_MIN;
03706         string low_thr_name = "low_threshold";
03707         if (params.has_key(low_thr_name)) {
03708                 low_threshold = params[low_thr_name];
03709         }
03710 
03711         float high_threshold = FLT_MAX;
03712         string high_thr_name = "high_threshold";
03713         if (params.has_key(high_thr_name)) {
03714                 high_threshold = params[high_thr_name];
03715         }
03716 
03717         float *rawp = image->get_data();
03718         float *refp = to->get_data();
03719 
03720         int nx = image->get_xsize();
03721         int ny = image->get_ysize();
03722         int nz = image->get_zsize();
03723         size_t size = nx * ny * nz;
03724 
03725         float sum_x = 0;
03726         float sum_y = 0;
03727         int count = 0;
03728 
03729         for (size_t i = 0; i < size; i++) {
03730                 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) {
03731                         count++;
03732                         sum_x += refp[i];
03733                         sum_y += rawp[i];
03734                 }
03735         }
03736 
03737         float sum_x_mean = sum_x / count;
03738         float sum_tt = 0;
03739         float b = 0;
03740 
03741         float t;
03742         for (size_t i = 0; i < size; i++) {
03743                 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) {
03744                         t = refp[i] - sum_x_mean;
03745                         sum_tt += t * t;
03746                         b += t * rawp[i];
03747                 }
03748         }
03749 
03750         b /= sum_tt;
03751 
03752         float a = (sum_y - sum_x * b) / count;
03753         float scale = 1 / b;
03754         float shift = -a / b;
03755 
03756         for (size_t i = 0; i < size; i++) {
03757                 rawp[i] = (rawp[i] - a) / b;
03758         }
03759 
03760         image->update();
03761 
03762         params["scale"] = scale;
03763         params["shift"] = shift;
03764 
03765         image->set_attr("norm_mult",scale);
03766         image->set_attr("norm_add",shift);
03767 
03768 }


Member Data Documentation

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

Definition at line 153 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:24 2010 for EMAN2 by  doxygen 1.3.9.1