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:

Inheritance graph
[legend]
Collaboration diagram for EMAN::BeamstopProcessor:

Collaboration graph
[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 3615 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 3630 of file processor.h.

03631                 {
03632                         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.";
03633                 }

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 3620 of file processor.h.

03621                 {
03622                         return NAME;
03623                 }

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 3635 of file processor.h.

References EMAN::TypeDict::put().

03636                 {
03637                         TypeDict d;
03638                         d.put("value1", EMObject::FLOAT, "sig multiplier");
03639                         d.put("value2", EMObject::FLOAT, "x of center");
03640                         d.put("value3", EMObject::FLOAT, "y of center");
03641                         return d;
03642                 }

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

Definition at line 3625 of file processor.h.

03626                 {
03627                         return new BeamstopProcessor();
03628                 }

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 2955 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().

02956 {
02957         if (!image) {
02958                 LOGWARN("NULL Image");
02959                 return;
02960         }
02961         if (image->get_zsize() > 1) {
02962                 LOGERR("BeamstopProcessor doesn't support 3D model");
02963                 throw ImageDimensionException("3D model not supported");
02964         }
02965 
02966         float value1 = params["value1"];
02967         float value2 = params["value2"];
02968         float value3 = params["value3"];
02969 
02970         float thr = fabs(value1);
02971         float *data = image->get_data();
02972         int cenx = (int) value2;
02973         int ceny = (int) value3;
02974 
02975         int nx = image->get_xsize();
02976         int ny = image->get_ysize();
02977 
02978         if (cenx <= 0) {
02979                 cenx = nx / 2;
02980         }
02981 
02982         if (ceny <= 0) {
02983                 ceny = ny / 2;
02984         }
02985 
02986         int mxr = (int) floor(sqrt(2.0f) * nx / 2);
02987 
02988         float *mean_values = new float[mxr];
02989         float *sigma_values = new float[mxr];
02990         double sum = 0;
02991         int count = 0;
02992         double square_sum = 0;
02993 
02994         for (int i = 0; i < mxr; i++) {
02995                 sum = 0;
02996                 count = 0;
02997                 square_sum = 0;
02998                 int nitems = 6 * i + 2;
02999 
03000                 for (int j = 0; j < nitems; j++) {
03001                         float ang = j * 2 * M_PI / nitems;
03002                         int x0 = (int) floor(cos(ang) * i + cenx);
03003                         int y0 = (int) floor(sin(ang) * i + ceny);
03004 
03005                         if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03006                                 continue;
03007                         }
03008 
03009                         float f = data[x0 + y0 * nx];
03010                         sum += f;
03011                         square_sum += f * f;
03012                         count++;
03013                 }
03014 
03015                 mean_values[i] = (float)sum / count;
03016                 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03017         }
03018 
03019 
03020         for (int k = 0; k < 5; k++) {
03021                 for (int i = 0; i < mxr; i++) {
03022                         sum = 0;
03023                         count = 0;
03024                         square_sum = 0;
03025                         int nitems = 6 * i + 2;
03026                         double thr1 = mean_values[i] - sigma_values[i] * thr;
03027                         double thr2 = mean_values[i] + sigma_values[i];
03028 
03029                         for (int j = 0; j < nitems; j++) {
03030                                 float ang = j * 2 * M_PI / nitems;
03031                                 int x0 = (int) floor(cos(ang) * i + cenx);
03032                                 int y0 = (int) floor(sin(ang) * i + ceny);
03033 
03034                                 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03035                                         data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03036                                         continue;
03037                                 }
03038 
03039                                 sum += data[x0 + y0 * nx];
03040                                 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03041                                 count++;
03042                         }
03043 
03044                         mean_values[i] = (float) sum / count;
03045                         sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03046                 }
03047         }
03048 
03049         for (int i = 0; i < nx; i++) {
03050                 for (int j = 0; j < ny; j++) {
03051 
03052 #ifdef  _WIN32
03053                         int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03054 #else
03055                         int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03056 #endif  //_WIN32
03057 
03058                         if (value1 < 0) {
03059                                 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03060                                         data[i + j * nx] = 0;
03061                                 }
03062                                 else {
03063                                         data[i + j * nx] -= mean_values[r];
03064                                 }
03065                                 continue;
03066                         }
03067                         if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03068                                 continue;
03069                         }
03070                         data[i + j * nx] = mean_values[r];
03071                 }
03072         }
03073 
03074         if( mean_values )
03075         {
03076                 delete[]mean_values;
03077                 mean_values = 0;
03078         }
03079 
03080         if( sigma_values )
03081         {
03082                 delete[]sigma_values;
03083                 sigma_values = 0;
03084         }
03085 
03086         image->update();
03087 }


Member Data Documentation

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

Definition at line 130 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:01 2010 for EMAN2 by  doxygen 1.3.9.1