#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 4333 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 4358 of file processor.h. 04359 { 04360 return "use least square method to normalize"; 04361 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4338 of file processor.h. 04339 {
04340 return NAME;
04341 }
|
|
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 4348 of file processor.h. References EMAN::TypeDict::put(). 04349 { 04350 TypeDict d; 04351 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04352 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04353 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)"); 04354 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)"); 04355 return d; 04356 }
|
|
Definition at line 4343 of file processor.h. 04344 { 04345 return new NormalizeToLeastSquareProcessor(); 04346 }
|
|
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 3742 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(). 03743 { 03744 if (!image) { 03745 LOGWARN("NULL Image"); 03746 return; 03747 } 03748 03749 EMData *to = params["to"]; 03750 03751 bool ignore_zero = params.set_default("ignore_zero",true); 03752 03753 float low_threshold = FLT_MIN; 03754 string low_thr_name = "low_threshold"; 03755 if (params.has_key(low_thr_name)) { 03756 low_threshold = params[low_thr_name]; 03757 } 03758 03759 float high_threshold = FLT_MAX; 03760 string high_thr_name = "high_threshold"; 03761 if (params.has_key(high_thr_name)) { 03762 high_threshold = params[high_thr_name]; 03763 } 03764 03765 float *rawp = image->get_data(); 03766 float *refp = to->get_data(); 03767 03768 int nx = image->get_xsize(); 03769 int ny = image->get_ysize(); 03770 int nz = image->get_zsize(); 03771 size_t size = (size_t)nx * ny * nz; 03772 03773 float sum_x = 0; 03774 float sum_y = 0; 03775 size_t count = 0; 03776 03777 float sum_x_mean = 0; 03778 float sum_tt = 0; 03779 float b = 0; 03780 03781 // This is really inefficient, who coded it ? --steve 03782 if (ignore_zero) { 03783 for (size_t i = 0; i < size; ++i) { 03784 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03785 count++; 03786 sum_x += refp[i]; 03787 sum_y += rawp[i]; 03788 } 03789 } 03790 03791 sum_x_mean = sum_x / count; 03792 sum_tt = 0; 03793 b = 0; 03794 03795 float t; 03796 for (size_t i = 0; i < size; ++i) { 03797 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03798 t = refp[i] - sum_x_mean; 03799 sum_tt += t * t; 03800 b += t * rawp[i]; 03801 } 03802 } 03803 } 03804 else { 03805 for (size_t i = 0; i < size; ++i) { 03806 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03807 count++; 03808 sum_x += refp[i]; 03809 sum_y += rawp[i]; 03810 } 03811 } 03812 03813 sum_x_mean = sum_x / count; 03814 sum_tt = 0; 03815 b = 0; 03816 03817 float t; 03818 for (size_t i = 0; i < size; ++i) { 03819 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03820 t = refp[i] - sum_x_mean; 03821 sum_tt += t * t; 03822 b += t * rawp[i]; 03823 } 03824 } 03825 } 03826 03827 b /= sum_tt; 03828 03829 float a = (sum_y - sum_x * b) / count; 03830 float scale = 1 / b; 03831 float shift = -a / b; 03832 03833 for (size_t i = 0; i < size; ++i) { 03834 rawp[i] = (rawp[i] - a) / b; 03835 } 03836 03837 image->update(); 03838 03839 params["scale"] = scale; 03840 params["shift"] = shift; 03841 03842 image->set_attr("norm_mult",scale); 03843 image->set_attr("norm_add",shift); 03844 03845 }
|
|
Definition at line 153 of file processor.cpp. |