#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 4447 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 4472 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 4452 of file processor.h.
References NAME.
04453 { 04454 return NAME; 04455 }
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 4462 of file processor.h.
References EMAN::EMObject::BOOL, EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
04463 { 04464 TypeDict d; 04465 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04466 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04467 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)"); 04468 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)"); 04469 return d; 04470 }
static Processor* EMAN::NormalizeToLeastSquareProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4457 of file processor.h.
04458 { 04459 return new NormalizeToLeastSquareProcessor(); 04460 }
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 3857 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().
03858 { 03859 if (!image) { 03860 LOGWARN("NULL Image"); 03861 return; 03862 } 03863 03864 EMData *to = params["to"]; 03865 03866 bool ignore_zero = params.set_default("ignore_zero",true); 03867 03868 float low_threshold = FLT_MIN; 03869 string low_thr_name = "low_threshold"; 03870 if (params.has_key(low_thr_name)) { 03871 low_threshold = params[low_thr_name]; 03872 } 03873 03874 float high_threshold = FLT_MAX; 03875 string high_thr_name = "high_threshold"; 03876 if (params.has_key(high_thr_name)) { 03877 high_threshold = params[high_thr_name]; 03878 } 03879 03880 float *rawp = image->get_data(); 03881 float *refp = to->get_data(); 03882 03883 int nx = image->get_xsize(); 03884 int ny = image->get_ysize(); 03885 int nz = image->get_zsize(); 03886 size_t size = (size_t)nx * ny * nz; 03887 03888 float sum_x = 0; 03889 float sum_y = 0; 03890 size_t count = 0; 03891 03892 float sum_x_mean = 0; 03893 float sum_tt = 0; 03894 float b = 0; 03895 03896 // This is really inefficient, who coded it ? --steve 03897 if (ignore_zero) { 03898 for (size_t i = 0; i < size; ++i) { 03899 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03900 count++; 03901 sum_x += refp[i]; 03902 sum_y += rawp[i]; 03903 } 03904 } 03905 03906 sum_x_mean = sum_x / count; 03907 sum_tt = 0; 03908 b = 0; 03909 03910 float t; 03911 for (size_t i = 0; i < size; ++i) { 03912 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03913 t = refp[i] - sum_x_mean; 03914 sum_tt += t * t; 03915 b += t * rawp[i]; 03916 } 03917 } 03918 } 03919 else { 03920 for (size_t i = 0; i < size; ++i) { 03921 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03922 count++; 03923 sum_x += refp[i]; 03924 sum_y += rawp[i]; 03925 } 03926 } 03927 03928 sum_x_mean = sum_x / count; 03929 sum_tt = 0; 03930 b = 0; 03931 03932 float t; 03933 for (size_t i = 0; i < size; ++i) { 03934 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03935 t = refp[i] - sum_x_mean; 03936 sum_tt += t * t; 03937 b += t * rawp[i]; 03938 } 03939 } 03940 } 03941 03942 b /= sum_tt; 03943 03944 float a = (sum_y - sum_x * b) / count; 03945 float scale = 1 / b; 03946 float shift = -a / b; 03947 03948 for (size_t i = 0; i < size; ++i) { 03949 rawp[i] = (rawp[i] - a) / b; 03950 } 03951 03952 image->update(); 03953 03954 params["scale"] = scale; 03955 params["shift"] = shift; 03956 03957 image->set_attr("norm_mult",scale); 03958 image->set_attr("norm_add",shift); 03959 03960 }
const string NormalizeToLeastSquareProcessor::NAME = "normalize.toimage" [static] |