#include <processor.h>
Inheritance diagram for EMAN::NormalizeToLeastSquareProcessor:
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 Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "normalize.toimage" |
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 4449 of file processor.h.
string EMAN::NormalizeToLeastSquareProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 4474 of file processor.h.
string EMAN::NormalizeToLeastSquareProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4454 of file processor.h.
References NAME.
04455 { 04456 return NAME; 04457 }
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.
Reimplemented from EMAN::Processor.
Definition at line 4464 of file processor.h.
References EMAN::EMObject::BOOL, EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
04465 { 04466 TypeDict d; 04467 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04468 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04469 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)"); 04470 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)"); 04471 return d; 04472 }
static Processor* EMAN::NormalizeToLeastSquareProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4459 of file processor.h.
04460 { 04461 return new NormalizeToLeastSquareProcessor(); 04462 }
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 3863 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().
03864 { 03865 if (!image) { 03866 LOGWARN("NULL Image"); 03867 return; 03868 } 03869 03870 EMData *to = params["to"]; 03871 03872 bool ignore_zero = params.set_default("ignore_zero",true); 03873 03874 float low_threshold = FLT_MIN; 03875 string low_thr_name = "low_threshold"; 03876 if (params.has_key(low_thr_name)) { 03877 low_threshold = params[low_thr_name]; 03878 } 03879 03880 float high_threshold = FLT_MAX; 03881 string high_thr_name = "high_threshold"; 03882 if (params.has_key(high_thr_name)) { 03883 high_threshold = params[high_thr_name]; 03884 } 03885 03886 float *rawp = image->get_data(); 03887 float *refp = to->get_data(); 03888 03889 int nx = image->get_xsize(); 03890 int ny = image->get_ysize(); 03891 int nz = image->get_zsize(); 03892 size_t size = (size_t)nx * ny * nz; 03893 03894 float sum_x = 0; 03895 float sum_y = 0; 03896 size_t count = 0; 03897 03898 float sum_x_mean = 0; 03899 float sum_tt = 0; 03900 float b = 0; 03901 03902 // This is really inefficient, who coded it ? --steve 03903 if (ignore_zero) { 03904 for (size_t i = 0; i < size; ++i) { 03905 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03906 count++; 03907 sum_x += refp[i]; 03908 sum_y += rawp[i]; 03909 } 03910 } 03911 03912 sum_x_mean = sum_x / count; 03913 sum_tt = 0; 03914 b = 0; 03915 03916 float t; 03917 for (size_t i = 0; i < size; ++i) { 03918 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03919 t = refp[i] - sum_x_mean; 03920 sum_tt += t * t; 03921 b += t * rawp[i]; 03922 } 03923 } 03924 } 03925 else { 03926 for (size_t i = 0; i < size; ++i) { 03927 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03928 count++; 03929 sum_x += refp[i]; 03930 sum_y += rawp[i]; 03931 } 03932 } 03933 03934 sum_x_mean = sum_x / count; 03935 sum_tt = 0; 03936 b = 0; 03937 03938 float t; 03939 for (size_t i = 0; i < size; ++i) { 03940 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03941 t = refp[i] - sum_x_mean; 03942 sum_tt += t * t; 03943 b += t * rawp[i]; 03944 } 03945 } 03946 } 03947 03948 b /= sum_tt; 03949 03950 float a = (sum_y - sum_x * b) / count; 03951 float scale = 1 / b; 03952 float shift = -a / b; 03953 03954 for (size_t i = 0; i < size; ++i) { 03955 rawp[i] = (rawp[i] - a) / b; 03956 } 03957 03958 image->update(); 03959 03960 params["scale"] = scale; 03961 params["shift"] = shift; 03962 03963 image->set_attr("norm_mult",scale); 03964 image->set_attr("norm_add",shift); 03965 03966 }
const string NormalizeToLeastSquareProcessor::NAME = "normalize.toimage" [static] |