#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 3794 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 3809 of file processor.h. 03810 {
03811 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.";
03812 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 3799 of file processor.h. 03800 {
03801 return NAME;
03802 }
|
|
|
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 3814 of file processor.h. References EMAN::TypeDict::put(). 03815 {
03816 TypeDict d;
03817 d.put("value1", EMObject::FLOAT, "sig multiplier");
03818 d.put("value2", EMObject::FLOAT, "x of center");
03819 d.put("value3", EMObject::FLOAT, "y of center");
03820 return d;
03821 }
|
|
|
Definition at line 3804 of file processor.h. 03805 {
03806 return new BeamstopProcessor();
03807 }
|
|
|
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 3075 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(). 03076 {
03077 if (!image) {
03078 LOGWARN("NULL Image");
03079 return;
03080 }
03081 if (image->get_zsize() > 1) {
03082 LOGERR("BeamstopProcessor doesn't support 3D model");
03083 throw ImageDimensionException("3D model not supported");
03084 }
03085
03086 float value1 = params["value1"];
03087 float value2 = params["value2"];
03088 float value3 = params["value3"];
03089
03090 float thr = fabs(value1);
03091 float *data = image->get_data();
03092 int cenx = (int) value2;
03093 int ceny = (int) value3;
03094
03095 int nx = image->get_xsize();
03096 int ny = image->get_ysize();
03097
03098 if (cenx <= 0) {
03099 cenx = nx / 2;
03100 }
03101
03102 if (ceny <= 0) {
03103 ceny = ny / 2;
03104 }
03105
03106 int mxr = (int) floor(sqrt(2.0f) * nx / 2);
03107
03108 float *mean_values = new float[mxr];
03109 float *sigma_values = new float[mxr];
03110 double sum = 0;
03111 int count = 0;
03112 double square_sum = 0;
03113
03114 for (int i = 0; i < mxr; i++) {
03115 sum = 0;
03116 count = 0;
03117 square_sum = 0;
03118 int nitems = 6 * i + 2;
03119
03120 for (int j = 0; j < nitems; j++) {
03121 float ang = j * 2 * M_PI / nitems;
03122 int x0 = (int) floor(cos(ang) * i + cenx);
03123 int y0 = (int) floor(sin(ang) * i + ceny);
03124
03125 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03126 continue;
03127 }
03128
03129 float f = data[x0 + y0 * nx];
03130 sum += f;
03131 square_sum += f * f;
03132 count++;
03133 }
03134
03135 mean_values[i] = (float)sum / count;
03136 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03137 }
03138
03139
03140 for (int k = 0; k < 5; k++) {
03141 for (int i = 0; i < mxr; i++) {
03142 sum = 0;
03143 count = 0;
03144 square_sum = 0;
03145 int nitems = 6 * i + 2;
03146 double thr1 = mean_values[i] - sigma_values[i] * thr;
03147 double thr2 = mean_values[i] + sigma_values[i];
03148
03149 for (int j = 0; j < nitems; j++) {
03150 float ang = j * 2 * M_PI / nitems;
03151 int x0 = (int) floor(cos(ang) * i + cenx);
03152 int y0 = (int) floor(sin(ang) * i + ceny);
03153
03154 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03155 data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03156 continue;
03157 }
03158
03159 sum += data[x0 + y0 * nx];
03160 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03161 count++;
03162 }
03163
03164 mean_values[i] = (float) sum / count;
03165 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03166 }
03167 }
03168
03169 for (int i = 0; i < nx; i++) {
03170 for (int j = 0; j < ny; j++) {
03171
03172 #ifdef _WIN32
03173 int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03174 #else
03175 int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03176 #endif //_WIN32
03177
03178 if (value1 < 0) {
03179 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03180 data[i + j * nx] = 0;
03181 }
03182 else {
03183 data[i + j * nx] -= mean_values[r];
03184 }
03185 continue;
03186 }
03187 if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03188 continue;
03189 }
03190 data[i + j * nx] = mean_values[r];
03191 }
03192 }
03193
03194 if( mean_values )
03195 {
03196 delete[]mean_values;
03197 mean_values = 0;
03198 }
03199
03200 if( sigma_values )
03201 {
03202 delete[]sigma_values;
03203 sigma_values = 0;
03204 }
03205
03206 image->update();
03207 }
|
|
|
Definition at line 141 of file processor.cpp. |
1.3.9.1