Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::BeamstopProcessor Class Reference

Try to eliminate beamstop in electron diffraction patterns. More...

#include <processor.h>

Inheritance diagram for EMAN::BeamstopProcessor:

[legend]
Collaboration diagram for EMAN::BeamstopProcessor:
[legend]
List of all members.

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

ProcessorNEW ()

Static Public Attributes

const string NAME = "mask.beamstop"

Detailed Description

Try to eliminate beamstop in electron diffraction patterns.

If value1<0 also does radial subtract.

Parameters:
value1 sig multiplier
value2 x of center
value3 y of center

Definition at line 3791 of file processor.h.


Member Function Documentation

string EMAN::BeamstopProcessor::get_desc  )  const [inline, virtual]
 

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 3806 of file processor.h.

03807                 {
03808                         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.";
03809                 }

string EMAN::BeamstopProcessor::get_name  )  const [inline, virtual]
 

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 3796 of file processor.h.

03797                 {
03798                         return NAME;
03799                 }

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.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 3811 of file processor.h.

References EMAN::TypeDict::put().

03812                 {
03813                         TypeDict d;
03814                         d.put("value1", EMObject::FLOAT, "sig multiplier");
03815                         d.put("value2", EMObject::FLOAT, "x of center");
03816                         d.put("value3", EMObject::FLOAT, "y of center");
03817                         return d;
03818                 }

Processor* EMAN::BeamstopProcessor::NEW  )  [inline, static]
 

Definition at line 3801 of file processor.h.

03802                 {
03803                         return new BeamstopProcessor();
03804                 }

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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 3000 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().

03001 {
03002         if (!image) {
03003                 LOGWARN("NULL Image");
03004                 return;
03005         }
03006         if (image->get_zsize() > 1) {
03007                 LOGERR("BeamstopProcessor doesn't support 3D model");
03008                 throw ImageDimensionException("3D model not supported");
03009         }
03010 
03011         float value1 = params["value1"];
03012         float value2 = params["value2"];
03013         float value3 = params["value3"];
03014 
03015         float thr = fabs(value1);
03016         float *data = image->get_data();
03017         int cenx = (int) value2;
03018         int ceny = (int) value3;
03019 
03020         int nx = image->get_xsize();
03021         int ny = image->get_ysize();
03022 
03023         if (cenx <= 0) {
03024                 cenx = nx / 2;
03025         }
03026 
03027         if (ceny <= 0) {
03028                 ceny = ny / 2;
03029         }
03030 
03031         int mxr = (int) floor(sqrt(2.0f) * nx / 2);
03032 
03033         float *mean_values = new float[mxr];
03034         float *sigma_values = new float[mxr];
03035         double sum = 0;
03036         int count = 0;
03037         double square_sum = 0;
03038 
03039         for (int i = 0; i < mxr; i++) {
03040                 sum = 0;
03041                 count = 0;
03042                 square_sum = 0;
03043                 int nitems = 6 * i + 2;
03044 
03045                 for (int j = 0; j < nitems; j++) {
03046                         float ang = j * 2 * M_PI / nitems;
03047                         int x0 = (int) floor(cos(ang) * i + cenx);
03048                         int y0 = (int) floor(sin(ang) * i + ceny);
03049 
03050                         if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03051                                 continue;
03052                         }
03053 
03054                         float f = data[x0 + y0 * nx];
03055                         sum += f;
03056                         square_sum += f * f;
03057                         count++;
03058                 }
03059 
03060                 mean_values[i] = (float)sum / count;
03061                 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03062         }
03063 
03064 
03065         for (int k = 0; k < 5; k++) {
03066                 for (int i = 0; i < mxr; i++) {
03067                         sum = 0;
03068                         count = 0;
03069                         square_sum = 0;
03070                         int nitems = 6 * i + 2;
03071                         double thr1 = mean_values[i] - sigma_values[i] * thr;
03072                         double thr2 = mean_values[i] + sigma_values[i];
03073 
03074                         for (int j = 0; j < nitems; j++) {
03075                                 float ang = j * 2 * M_PI / nitems;
03076                                 int x0 = (int) floor(cos(ang) * i + cenx);
03077                                 int y0 = (int) floor(sin(ang) * i + ceny);
03078 
03079                                 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03080                                         data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03081                                         continue;
03082                                 }
03083 
03084                                 sum += data[x0 + y0 * nx];
03085                                 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03086                                 count++;
03087                         }
03088 
03089                         mean_values[i] = (float) sum / count;
03090                         sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03091                 }
03092         }
03093 
03094         for (int i = 0; i < nx; i++) {
03095                 for (int j = 0; j < ny; j++) {
03096 
03097 #ifdef  _WIN32
03098                         int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03099 #else
03100                         int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03101 #endif  //_WIN32
03102 
03103                         if (value1 < 0) {
03104                                 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03105                                         data[i + j * nx] = 0;
03106                                 }
03107                                 else {
03108                                         data[i + j * nx] -= mean_values[r];
03109                                 }
03110                                 continue;
03111                         }
03112                         if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03113                                 continue;
03114                         }
03115                         data[i + j * nx] = mean_values[r];
03116                 }
03117         }
03118 
03119         if( mean_values )
03120         {
03121                 delete[]mean_values;
03122                 mean_values = 0;
03123         }
03124 
03125         if( sigma_values )
03126         {
03127                 delete[]sigma_values;
03128                 sigma_values = 0;
03129         }
03130 
03131         image->update();
03132 }


Member Data Documentation

const string BeamstopProcessor::NAME = "mask.beamstop" [static]
 

Definition at line 135 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:23 2010 for EMAN2 by  doxygen 1.3.9.1