#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 | |
| Processor * | NEW () |
Static Public Attributes | |
| 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 3756 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 3771 of file processor.h. 03772 {
03773 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.";
03774 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3761 of file processor.h. 03762 {
03763 return NAME;
03764 }
|
|
|
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 3776 of file processor.h. References EMAN::TypeDict::put(). 03777 {
03778 TypeDict d;
03779 d.put("value1", EMObject::FLOAT, "sig multiplier");
03780 d.put("value2", EMObject::FLOAT, "x of center");
03781 d.put("value3", EMObject::FLOAT, "y of center");
03782 return d;
03783 }
|
|
|
Definition at line 3766 of file processor.h. 03767 {
03768 return new BeamstopProcessor();
03769 }
|
|
|
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 3047 of file processor.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, LOGWARN, nx, ny, EMAN::Util::round(), sqrt(), and EMAN::EMData::update(). 03048 {
03049 if (!image) {
03050 LOGWARN("NULL Image");
03051 return;
03052 }
03053 if (image->get_zsize() > 1) {
03054 LOGERR("BeamstopProcessor doesn't support 3D model");
03055 throw ImageDimensionException("3D model not supported");
03056 }
03057
03058 float value1 = params["value1"];
03059 float value2 = params["value2"];
03060 float value3 = params["value3"];
03061
03062 float thr = fabs(value1);
03063 float *data = image->get_data();
03064 int cenx = (int) value2;
03065 int ceny = (int) value3;
03066
03067 int nx = image->get_xsize();
03068 int ny = image->get_ysize();
03069
03070 if (cenx <= 0) {
03071 cenx = nx / 2;
03072 }
03073
03074 if (ceny <= 0) {
03075 ceny = ny / 2;
03076 }
03077
03078 int mxr = (int) floor(sqrt(2.0f) * nx / 2);
03079
03080 float *mean_values = new float[mxr];
03081 float *sigma_values = new float[mxr];
03082 double sum = 0;
03083 int count = 0;
03084 double square_sum = 0;
03085
03086 for (int i = 0; i < mxr; i++) {
03087 sum = 0;
03088 count = 0;
03089 square_sum = 0;
03090 int nitems = 6 * i + 2;
03091
03092 for (int j = 0; j < nitems; j++) {
03093 float ang = j * 2 * M_PI / nitems;
03094 int x0 = (int) floor(cos(ang) * i + cenx);
03095 int y0 = (int) floor(sin(ang) * i + ceny);
03096
03097 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03098 continue;
03099 }
03100
03101 float f = data[x0 + y0 * nx];
03102 sum += f;
03103 square_sum += f * f;
03104 count++;
03105 }
03106
03107 mean_values[i] = (float)sum / count;
03108 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03109 }
03110
03111
03112 for (int k = 0; k < 5; k++) {
03113 for (int i = 0; i < mxr; i++) {
03114 sum = 0;
03115 count = 0;
03116 square_sum = 0;
03117 int nitems = 6 * i + 2;
03118 double thr1 = mean_values[i] - sigma_values[i] * thr;
03119 double thr2 = mean_values[i] + sigma_values[i];
03120
03121 for (int j = 0; j < nitems; j++) {
03122 float ang = j * 2 * M_PI / nitems;
03123 int x0 = (int) floor(cos(ang) * i + cenx);
03124 int y0 = (int) floor(sin(ang) * i + ceny);
03125
03126 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03127 data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03128 continue;
03129 }
03130
03131 sum += data[x0 + y0 * nx];
03132 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03133 count++;
03134 }
03135
03136 mean_values[i] = (float) sum / count;
03137 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03138 }
03139 }
03140
03141 for (int i = 0; i < nx; i++) {
03142 for (int j = 0; j < ny; j++) {
03143
03144 #ifdef _WIN32
03145 int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03146 #else
03147 int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03148 #endif //_WIN32
03149
03150 if (value1 < 0) {
03151 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03152 data[i + j * nx] = 0;
03153 }
03154 else {
03155 data[i + j * nx] -= mean_values[r];
03156 }
03157 continue;
03158 }
03159 if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03160 continue;
03161 }
03162 data[i + j * nx] = mean_values[r];
03163 }
03164 }
03165
03166 if( mean_values )
03167 {
03168 delete[]mean_values;
03169 mean_values = 0;
03170 }
03171
03172 if( sigma_values )
03173 {
03174 delete[]sigma_values;
03175 sigma_values = 0;
03176 }
03177
03178 image->update();
03179 }
|
|
|
Definition at line 135 of file processor.cpp. |
1.3.9.1