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

static ProcessorNEW ()

Static Public Attributes

static 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 3870 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 3885 of file processor.h.

03886                 {
03887                         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.";
03888                 }

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

References NAME.

03876                 {
03877                         return NAME;
03878                 }

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

References EMAN::EMObject::FLOAT, and EMAN::TypeDict::put().

03891                 {
03892                         TypeDict d;
03893                         d.put("value1", EMObject::FLOAT, "sig multiplier");
03894                         d.put("value2", EMObject::FLOAT, "x of center");
03895                         d.put("value3", EMObject::FLOAT, "y of center");
03896                         return d;
03897                 }

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

Definition at line 3880 of file processor.h.

03881                 {
03882                         return new BeamstopProcessor();
03883                 }

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

03167 {
03168         if (!image) {
03169                 LOGWARN("NULL Image");
03170                 return;
03171         }
03172         if (image->get_zsize() > 1) {
03173                 LOGERR("BeamstopProcessor doesn't support 3D model");
03174                 throw ImageDimensionException("3D model not supported");
03175         }
03176 
03177         float value1 = params["value1"];
03178         float value2 = params["value2"];
03179         float value3 = params["value3"];
03180 
03181         float thr = fabs(value1);
03182         float *data = image->get_data();
03183         int cenx = (int) value2;
03184         int ceny = (int) value3;
03185 
03186         int nx = image->get_xsize();
03187         int ny = image->get_ysize();
03188 
03189         if (cenx <= 0) {
03190                 cenx = nx / 2;
03191         }
03192 
03193         if (ceny <= 0) {
03194                 ceny = ny / 2;
03195         }
03196 
03197         int mxr = (int) floor(sqrt(2.0f) * nx / 2);
03198 
03199         float *mean_values = new float[mxr];
03200         float *sigma_values = new float[mxr];
03201         double sum = 0;
03202         int count = 0;
03203         double square_sum = 0;
03204 
03205         for (int i = 0; i < mxr; i++) {
03206                 sum = 0;
03207                 count = 0;
03208                 square_sum = 0;
03209                 int nitems = 6 * i + 2;
03210 
03211                 for (int j = 0; j < nitems; j++) {
03212                         float ang = j * 2 * M_PI / nitems;
03213                         int x0 = (int) floor(cos(ang) * i + cenx);
03214                         int y0 = (int) floor(sin(ang) * i + ceny);
03215 
03216                         if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03217                                 continue;
03218                         }
03219 
03220                         float f = data[x0 + y0 * nx];
03221                         sum += f;
03222                         square_sum += f * f;
03223                         count++;
03224                 }
03225 
03226                 mean_values[i] = (float)sum / count;
03227                 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03228         }
03229 
03230 
03231         for (int k = 0; k < 5; k++) {
03232                 for (int i = 0; i < mxr; i++) {
03233                         sum = 0;
03234                         count = 0;
03235                         square_sum = 0;
03236                         int nitems = 6 * i + 2;
03237                         double thr1 = mean_values[i] - sigma_values[i] * thr;
03238                         double thr2 = mean_values[i] + sigma_values[i];
03239 
03240                         for (int j = 0; j < nitems; j++) {
03241                                 float ang = j * 2 * M_PI / nitems;
03242                                 int x0 = (int) floor(cos(ang) * i + cenx);
03243                                 int y0 = (int) floor(sin(ang) * i + ceny);
03244 
03245                                 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03246                                         data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03247                                         continue;
03248                                 }
03249 
03250                                 sum += data[x0 + y0 * nx];
03251                                 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03252                                 count++;
03253                         }
03254 
03255                         mean_values[i] = (float) sum / count;
03256                         sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03257                 }
03258         }
03259 
03260         for (int i = 0; i < nx; i++) {
03261                 for (int j = 0; j < ny; j++) {
03262 
03263 #ifdef  _WIN32
03264                         int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03265 #else
03266                         int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03267 #endif  //_WIN32
03268 
03269                         if (value1 < 0) {
03270                                 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03271                                         data[i + j * nx] = 0;
03272                                 }
03273                                 else {
03274                                         data[i + j * nx] -= mean_values[r];
03275                                 }
03276                                 continue;
03277                         }
03278                         if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03279                                 continue;
03280                         }
03281                         data[i + j * nx] = mean_values[r];
03282                 }
03283         }
03284 
03285         if( mean_values )
03286         {
03287                 delete[]mean_values;
03288                 mean_values = 0;
03289         }
03290 
03291         if( sigma_values )
03292         {
03293                 delete[]sigma_values;
03294                 sigma_values = 0;
03295         }
03296 
03297         image->update();
03298 }


Member Data Documentation

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

Definition at line 3899 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:10:18 2012 for EMAN2 by  doxygen 1.4.7