#include <processor.h>
Inheritance diagram for EMAN::BeamstopProcessor:
Public Member Functions | |
void | process_inplace (EMData *image) |
To process an image in-place. | |
string | get_name () const |
Get the processor's name. | |
string | get_desc () const |
Get the descrition of this specific processor. | |
TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "mask.beamstop" |
If value1<0 also does radial subtract.
value1 | sig multiplier | |
value2 | x of center | |
value3 | y of center |
Definition at line 3700 of file processor.h.
string EMAN::BeamstopProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 3715 of file processor.h.
03716 { 03717 return "Try to eliminate beamstop in electron diffraction patterns. value1=sig multiplier; value2,value3 are x,y of center, if value1<0 also does radial subtract."; 03718 }
string EMAN::BeamstopProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 3705 of file processor.h.
References NAME.
03706 { 03707 return NAME; 03708 }
TypeDict EMAN::BeamstopProcessor::get_param_types | ( | ) | const [inline, virtual] |
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 3720 of file processor.h.
References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().
03721 { 03722 TypeDict d; 03723 d.put("value1", EMObject::FLOAT, "sig multiplier"); 03724 d.put("value2", EMObject::FLOAT, "x of center"); 03725 d.put("value3", EMObject::FLOAT, "y of center"); 03726 return d; 03727 }
static Processor* EMAN::BeamstopProcessor::NEW | ( | ) | [inline, static] |
void BeamstopProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 3016 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, LOGWARN, EMAN::Processor::params, EMAN::Util::round(), sqrt(), and EMAN::EMData::update().
03017 { 03018 if (!image) { 03019 LOGWARN("NULL Image"); 03020 return; 03021 } 03022 if (image->get_zsize() > 1) { 03023 LOGERR("BeamstopProcessor doesn't support 3D model"); 03024 throw ImageDimensionException("3D model not supported"); 03025 } 03026 03027 float value1 = params["value1"]; 03028 float value2 = params["value2"]; 03029 float value3 = params["value3"]; 03030 03031 float thr = fabs(value1); 03032 float *data = image->get_data(); 03033 int cenx = (int) value2; 03034 int ceny = (int) value3; 03035 03036 int nx = image->get_xsize(); 03037 int ny = image->get_ysize(); 03038 03039 if (cenx <= 0) { 03040 cenx = nx / 2; 03041 } 03042 03043 if (ceny <= 0) { 03044 ceny = ny / 2; 03045 } 03046 03047 int mxr = (int) floor(sqrt(2.0f) * nx / 2); 03048 03049 float *mean_values = new float[mxr]; 03050 float *sigma_values = new float[mxr]; 03051 double sum = 0; 03052 int count = 0; 03053 double square_sum = 0; 03054 03055 for (int i = 0; i < mxr; i++) { 03056 sum = 0; 03057 count = 0; 03058 square_sum = 0; 03059 int nitems = 6 * i + 2; 03060 03061 for (int j = 0; j < nitems; j++) { 03062 float ang = j * 2 * M_PI / nitems; 03063 int x0 = (int) floor(cos(ang) * i + cenx); 03064 int y0 = (int) floor(sin(ang) * i + ceny); 03065 03066 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) { 03067 continue; 03068 } 03069 03070 float f = data[x0 + y0 * nx]; 03071 sum += f; 03072 square_sum += f * f; 03073 count++; 03074 } 03075 03076 mean_values[i] = (float)sum / count; 03077 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]); 03078 } 03079 03080 03081 for (int k = 0; k < 5; k++) { 03082 for (int i = 0; i < mxr; i++) { 03083 sum = 0; 03084 count = 0; 03085 square_sum = 0; 03086 int nitems = 6 * i + 2; 03087 double thr1 = mean_values[i] - sigma_values[i] * thr; 03088 double thr2 = mean_values[i] + sigma_values[i]; 03089 03090 for (int j = 0; j < nitems; j++) { 03091 float ang = j * 2 * M_PI / nitems; 03092 int x0 = (int) floor(cos(ang) * i + cenx); 03093 int y0 = (int) floor(sin(ang) * i + ceny); 03094 03095 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny || 03096 data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) { 03097 continue; 03098 } 03099 03100 sum += data[x0 + y0 * nx]; 03101 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx]; 03102 count++; 03103 } 03104 03105 mean_values[i] = (float) sum / count; 03106 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]); 03107 } 03108 } 03109 03110 for (int i = 0; i < nx; i++) { 03111 for (int j = 0; j < ny; j++) { 03112 03113 #ifdef _WIN32 03114 int r = Util::round(_hypot((float) i - cenx, (float) j - ceny)); 03115 #else 03116 int r = Util::round(hypot((float) i - cenx, (float) j - ceny)); 03117 #endif //_WIN32 03118 03119 if (value1 < 0) { 03120 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) { 03121 data[i + j * nx] = 0; 03122 } 03123 else { 03124 data[i + j * nx] -= mean_values[r]; 03125 } 03126 continue; 03127 } 03128 if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) { 03129 continue; 03130 } 03131 data[i + j * nx] = mean_values[r]; 03132 } 03133 } 03134 03135 if( mean_values ) 03136 { 03137 delete[]mean_values; 03138 mean_values = 0; 03139 } 03140 03141 if( sigma_values ) 03142 { 03143 delete[]sigma_values; 03144 sigma_values = 0; 03145 } 03146 03147 image->update(); 03148 }
const string BeamstopProcessor::NAME = "mask.beamstop" [static] |