#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 4408 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 4433 of file processor.h.
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4413 of file processor.h. References NAME. 04414 { 04415 return NAME; 04416 }
|
|
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 4423 of file processor.h. References EMAN::EMObject::BOOL, EMAN::EMObject::EMDATA, EMAN::EMObject::FLOAT, and EMAN::TypeDict::put(). 04424 { 04425 TypeDict d; 04426 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04427 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04428 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)"); 04429 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)"); 04430 return d; 04431 }
|
|
Definition at line 4418 of file processor.h. 04419 { 04420 return new NormalizeToLeastSquareProcessor(); 04421 }
|
|
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 3803 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(). 03804 { 03805 if (!image) { 03806 LOGWARN("NULL Image"); 03807 return; 03808 } 03809 03810 EMData *to = params["to"]; 03811 03812 bool ignore_zero = params.set_default("ignore_zero",true); 03813 03814 float low_threshold = FLT_MIN; 03815 string low_thr_name = "low_threshold"; 03816 if (params.has_key(low_thr_name)) { 03817 low_threshold = params[low_thr_name]; 03818 } 03819 03820 float high_threshold = FLT_MAX; 03821 string high_thr_name = "high_threshold"; 03822 if (params.has_key(high_thr_name)) { 03823 high_threshold = params[high_thr_name]; 03824 } 03825 03826 float *rawp = image->get_data(); 03827 float *refp = to->get_data(); 03828 03829 int nx = image->get_xsize(); 03830 int ny = image->get_ysize(); 03831 int nz = image->get_zsize(); 03832 size_t size = nx * ny * nz; 03833 03834 float sum_x = 0; 03835 float sum_y = 0; 03836 int count = 0; 03837 03838 float sum_x_mean = 0; 03839 float sum_tt = 0; 03840 float b = 0; 03841 03842 // This is really inefficient, who coded it ? --steve 03843 if (ignore_zero) { 03844 for (size_t i = 0; i < size; i++) { 03845 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) { 03846 count++; 03847 sum_x += refp[i]; 03848 sum_y += rawp[i]; 03849 } 03850 } 03851 03852 sum_x_mean = sum_x / count; 03853 sum_tt = 0; 03854 b = 0; 03855 03856 float t; 03857 for (size_t i = 0; i < size; i++) { 03858 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) { 03859 t = refp[i] - sum_x_mean; 03860 sum_tt += t * t; 03861 b += t * rawp[i]; 03862 } 03863 } 03864 } 03865 else { 03866 for (size_t i = 0; i < size; i++) { 03867 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03868 count++; 03869 sum_x += refp[i]; 03870 sum_y += rawp[i]; 03871 } 03872 } 03873 03874 sum_x_mean = sum_x / count; 03875 sum_tt = 0; 03876 b = 0; 03877 03878 float t; 03879 for (size_t i = 0; i < size; i++) { 03880 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03881 t = refp[i] - sum_x_mean; 03882 sum_tt += t * t; 03883 b += t * rawp[i]; 03884 } 03885 } 03886 } 03887 03888 b /= sum_tt; 03889 03890 float a = (sum_y - sum_x * b) / count; 03891 float scale = 1 / b; 03892 float shift = -a / b; 03893 03894 for (size_t i = 0; i < size; i++) { 03895 rawp[i] = (rawp[i] - a) / b; 03896 } 03897 03898 image->update(); 03899 03900 params["scale"] = scale; 03901 params["shift"] = shift; 03902 03903 image->set_attr("norm_mult",scale); 03904 image->set_attr("norm_add",shift); 03905 03906 }
|
|
Definition at line 4438 of file processor.h. Referenced by get_name(). |