#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 | |
Processor * | NEW () |
Static Public Attributes | |
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.
|
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. 04473 { 04474 return "use least square method to normalize"; 04475 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4452 of file processor.h. 04453 {
04454 return NAME;
04455 }
|
|
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::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 }
|
|
Definition at line 4457 of file processor.h. 04458 { 04459 return new NormalizeToLeastSquareProcessor(); 04460 }
|
|
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.
Implements EMAN::Processor. Definition at line 3861 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(). 03862 { 03863 if (!image) { 03864 LOGWARN("NULL Image"); 03865 return; 03866 } 03867 03868 EMData *to = params["to"]; 03869 03870 bool ignore_zero = params.set_default("ignore_zero",true); 03871 03872 float low_threshold = FLT_MIN; 03873 string low_thr_name = "low_threshold"; 03874 if (params.has_key(low_thr_name)) { 03875 low_threshold = params[low_thr_name]; 03876 } 03877 03878 float high_threshold = FLT_MAX; 03879 string high_thr_name = "high_threshold"; 03880 if (params.has_key(high_thr_name)) { 03881 high_threshold = params[high_thr_name]; 03882 } 03883 03884 float *rawp = image->get_data(); 03885 float *refp = to->get_data(); 03886 03887 int nx = image->get_xsize(); 03888 int ny = image->get_ysize(); 03889 int nz = image->get_zsize(); 03890 size_t size = (size_t)nx * ny * nz; 03891 03892 float sum_x = 0; 03893 float sum_y = 0; 03894 size_t count = 0; 03895 03896 float sum_x_mean = 0; 03897 float sum_tt = 0; 03898 float b = 0; 03899 03900 // This is really inefficient, who coded it ? --steve 03901 if (ignore_zero) { 03902 for (size_t i = 0; i < size; ++i) { 03903 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03904 count++; 03905 sum_x += refp[i]; 03906 sum_y += rawp[i]; 03907 } 03908 } 03909 03910 sum_x_mean = sum_x / count; 03911 sum_tt = 0; 03912 b = 0; 03913 03914 float t; 03915 for (size_t i = 0; i < size; ++i) { 03916 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03917 t = refp[i] - sum_x_mean; 03918 sum_tt += t * t; 03919 b += t * rawp[i]; 03920 } 03921 } 03922 } 03923 else { 03924 for (size_t i = 0; i < size; ++i) { 03925 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03926 count++; 03927 sum_x += refp[i]; 03928 sum_y += rawp[i]; 03929 } 03930 } 03931 03932 sum_x_mean = sum_x / count; 03933 sum_tt = 0; 03934 b = 0; 03935 03936 float t; 03937 for (size_t i = 0; i < size; ++i) { 03938 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03939 t = refp[i] - sum_x_mean; 03940 sum_tt += t * t; 03941 b += t * rawp[i]; 03942 } 03943 } 03944 } 03945 03946 b /= sum_tt; 03947 03948 float a = (sum_y - sum_x * b) / count; 03949 float scale = 1 / b; 03950 float shift = -a / b; 03951 03952 for (size_t i = 0; i < size; ++i) { 03953 rawp[i] = (rawp[i] - a) / b; 03954 } 03955 03956 image->update(); 03957 03958 params["scale"] = scale; 03959 params["shift"] = shift; 03960 03961 image->set_attr("norm_mult",scale); 03962 image->set_attr("norm_add",shift); 03963 03964 }
|
|
Definition at line 154 of file processor.cpp. |