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

03888                 {
03889                         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.";
03890                 }

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

03878                 {
03879                         return NAME;
03880                 }

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

References EMAN::TypeDict::put().

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

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

Definition at line 3882 of file processor.h.

03883                 {
03884                         return new BeamstopProcessor();
03885                 }

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

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


Member Data Documentation

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

Definition at line 136 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:47 2013 for EMAN2 by  doxygen 1.3.9.1