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

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


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 Fri Aug 10 16:32:49 2012 for EMAN2 by  doxygen 1.4.7