#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 4277 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 4302 of file processor.h. 04303 { 04304 return "use least square method to normalize"; 04305 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4282 of file processor.h. 04283 {
04284 return NAME;
04285 }
|
|
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 4292 of file processor.h. References EMAN::TypeDict::put(). 04293 { 04294 TypeDict d; 04295 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04296 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04297 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)"); 04298 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)"); 04299 return d; 04300 }
|
|
Definition at line 4287 of file processor.h. 04288 { 04289 return new NormalizeToLeastSquareProcessor(); 04290 }
|
|
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 3711 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(). 03712 { 03713 if (!image) { 03714 LOGWARN("NULL Image"); 03715 return; 03716 } 03717 03718 EMData *to = params["to"]; 03719 03720 bool ignore_zero = params.set_default("ignore_zero",true); 03721 03722 float low_threshold = FLT_MIN; 03723 string low_thr_name = "low_threshold"; 03724 if (params.has_key(low_thr_name)) { 03725 low_threshold = params[low_thr_name]; 03726 } 03727 03728 float high_threshold = FLT_MAX; 03729 string high_thr_name = "high_threshold"; 03730 if (params.has_key(high_thr_name)) { 03731 high_threshold = params[high_thr_name]; 03732 } 03733 03734 float *rawp = image->get_data(); 03735 float *refp = to->get_data(); 03736 03737 int nx = image->get_xsize(); 03738 int ny = image->get_ysize(); 03739 int nz = image->get_zsize(); 03740 size_t size = (size_t)nx * ny * nz; 03741 03742 float sum_x = 0; 03743 float sum_y = 0; 03744 size_t count = 0; 03745 03746 float sum_x_mean = 0; 03747 float sum_tt = 0; 03748 float b = 0; 03749 03750 // This is really inefficient, who coded it ? --steve 03751 if (ignore_zero) { 03752 for (size_t i = 0; i < size; ++i) { 03753 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03754 count++; 03755 sum_x += refp[i]; 03756 sum_y += rawp[i]; 03757 } 03758 } 03759 03760 sum_x_mean = sum_x / count; 03761 sum_tt = 0; 03762 b = 0; 03763 03764 float t; 03765 for (size_t i = 0; i < size; ++i) { 03766 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0f && rawp[i] != 0.0f) { 03767 t = refp[i] - sum_x_mean; 03768 sum_tt += t * t; 03769 b += t * rawp[i]; 03770 } 03771 } 03772 } 03773 else { 03774 for (size_t i = 0; i < size; ++i) { 03775 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03776 count++; 03777 sum_x += refp[i]; 03778 sum_y += rawp[i]; 03779 } 03780 } 03781 03782 sum_x_mean = sum_x / count; 03783 sum_tt = 0; 03784 b = 0; 03785 03786 float t; 03787 for (size_t i = 0; i < size; ++i) { 03788 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03789 t = refp[i] - sum_x_mean; 03790 sum_tt += t * t; 03791 b += t * rawp[i]; 03792 } 03793 } 03794 } 03795 03796 b /= sum_tt; 03797 03798 float a = (sum_y - sum_x * b) / count; 03799 float scale = 1 / b; 03800 float shift = -a / b; 03801 03802 for (size_t i = 0; i < size; ++i) { 03803 rawp[i] = (rawp[i] - a) / b; 03804 } 03805 03806 image->update(); 03807 03808 params["scale"] = scale; 03809 params["shift"] = shift; 03810 03811 image->set_attr("norm_mult",scale); 03812 image->set_attr("norm_add",shift); 03813 03814 }
|
|
Definition at line 151 of file processor.cpp. |