#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 4192 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 4217 of file processor.h. 04218 { 04219 return "use least square method to normalize"; 04220 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4197 of file processor.h. 04198 {
04199 return NAME;
04200 }
|
|
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 4207 of file processor.h. References EMAN::TypeDict::put(). 04208 { 04209 TypeDict d; 04210 d.put("to", EMObject::EMDATA, "reference image normalize to"); 04211 d.put("ignore_zero", EMObject::BOOL, "If set, ignores any pixels which are exactly zero in either image. Defaut = True."); 04212 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)"); 04213 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)"); 04214 return d; 04215 }
|
|
Definition at line 4202 of file processor.h. 04203 { 04204 return new NormalizeToLeastSquareProcessor(); 04205 }
|
|
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 3651 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(). 03652 { 03653 if (!image) { 03654 LOGWARN("NULL Image"); 03655 return; 03656 } 03657 03658 EMData *to = params["to"]; 03659 03660 bool ignore_zero = params.set_default("ignore_zero",true); 03661 03662 float low_threshold = FLT_MIN; 03663 string low_thr_name = "low_threshold"; 03664 if (params.has_key(low_thr_name)) { 03665 low_threshold = params[low_thr_name]; 03666 } 03667 03668 float high_threshold = FLT_MAX; 03669 string high_thr_name = "high_threshold"; 03670 if (params.has_key(high_thr_name)) { 03671 high_threshold = params[high_thr_name]; 03672 } 03673 03674 float *rawp = image->get_data(); 03675 float *refp = to->get_data(); 03676 03677 int nx = image->get_xsize(); 03678 int ny = image->get_ysize(); 03679 int nz = image->get_zsize(); 03680 size_t size = nx * ny * nz; 03681 03682 float sum_x = 0; 03683 float sum_y = 0; 03684 int count = 0; 03685 03686 float sum_x_mean = 0; 03687 float sum_tt = 0; 03688 float b = 0; 03689 03690 // This is really inefficient, who coded it ? --steve 03691 if (ignore_zero) { 03692 for (size_t i = 0; i < size; i++) { 03693 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) { 03694 count++; 03695 sum_x += refp[i]; 03696 sum_y += rawp[i]; 03697 } 03698 } 03699 03700 sum_x_mean = sum_x / count; 03701 sum_tt = 0; 03702 b = 0; 03703 03704 float t; 03705 for (size_t i = 0; i < size; i++) { 03706 if (refp[i] >= low_threshold && refp[i] <= high_threshold && refp[i] != 0.0 && rawp[i] != 0.0) { 03707 t = refp[i] - sum_x_mean; 03708 sum_tt += t * t; 03709 b += t * rawp[i]; 03710 } 03711 } 03712 } 03713 else { 03714 for (size_t i = 0; i < size; i++) { 03715 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03716 count++; 03717 sum_x += refp[i]; 03718 sum_y += rawp[i]; 03719 } 03720 } 03721 03722 sum_x_mean = sum_x / count; 03723 sum_tt = 0; 03724 b = 0; 03725 03726 float t; 03727 for (size_t i = 0; i < size; i++) { 03728 if (refp[i] >= low_threshold && refp[i] <= high_threshold) { 03729 t = refp[i] - sum_x_mean; 03730 sum_tt += t * t; 03731 b += t * rawp[i]; 03732 } 03733 } 03734 } 03735 03736 b /= sum_tt; 03737 03738 float a = (sum_y - sum_x * b) / count; 03739 float scale = 1 / b; 03740 float shift = -a / b; 03741 03742 for (size_t i = 0; i < size; i++) { 03743 rawp[i] = (rawp[i] - a) / b; 03744 } 03745 03746 image->update(); 03747 03748 params["scale"] = scale; 03749 params["shift"] = shift; 03750 03751 image->set_attr("norm_mult",scale); 03752 image->set_attr("norm_add",shift); 03753 03754 }
|
|
Definition at line 148 of file processor.cpp. |