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

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

03847                 {
03848                         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.";
03849                 }

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

References NAME.

03837                 {
03838                         return NAME;
03839                 }

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

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

03852                 {
03853                         TypeDict d;
03854                         d.put("value1", EMObject::FLOAT, "sig multiplier");
03855                         d.put("value2", EMObject::FLOAT, "x of center");
03856                         d.put("value3", EMObject::FLOAT, "y of center");
03857                         return d;
03858                 }

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

Definition at line 3841 of file processor.h.

03842                 {
03843                         return new BeamstopProcessor();
03844                 }

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

03108 {
03109         if (!image) {
03110                 LOGWARN("NULL Image");
03111                 return;
03112         }
03113         if (image->get_zsize() > 1) {
03114                 LOGERR("BeamstopProcessor doesn't support 3D model");
03115                 throw ImageDimensionException("3D model not supported");
03116         }
03117 
03118         float value1 = params["value1"];
03119         float value2 = params["value2"];
03120         float value3 = params["value3"];
03121 
03122         float thr = fabs(value1);
03123         float *data = image->get_data();
03124         int cenx = (int) value2;
03125         int ceny = (int) value3;
03126 
03127         int nx = image->get_xsize();
03128         int ny = image->get_ysize();
03129 
03130         if (cenx <= 0) {
03131                 cenx = nx / 2;
03132         }
03133 
03134         if (ceny <= 0) {
03135                 ceny = ny / 2;
03136         }
03137 
03138         int mxr = (int) floor(sqrt(2.0f) * nx / 2);
03139 
03140         float *mean_values = new float[mxr];
03141         float *sigma_values = new float[mxr];
03142         double sum = 0;
03143         int count = 0;
03144         double square_sum = 0;
03145 
03146         for (int i = 0; i < mxr; i++) {
03147                 sum = 0;
03148                 count = 0;
03149                 square_sum = 0;
03150                 int nitems = 6 * i + 2;
03151 
03152                 for (int j = 0; j < nitems; j++) {
03153                         float ang = j * 2 * M_PI / nitems;
03154                         int x0 = (int) floor(cos(ang) * i + cenx);
03155                         int y0 = (int) floor(sin(ang) * i + ceny);
03156 
03157                         if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny) {
03158                                 continue;
03159                         }
03160 
03161                         float f = data[x0 + y0 * nx];
03162                         sum += f;
03163                         square_sum += f * f;
03164                         count++;
03165                 }
03166 
03167                 mean_values[i] = (float)sum / count;
03168                 sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03169         }
03170 
03171 
03172         for (int k = 0; k < 5; k++) {
03173                 for (int i = 0; i < mxr; i++) {
03174                         sum = 0;
03175                         count = 0;
03176                         square_sum = 0;
03177                         int nitems = 6 * i + 2;
03178                         double thr1 = mean_values[i] - sigma_values[i] * thr;
03179                         double thr2 = mean_values[i] + sigma_values[i];
03180 
03181                         for (int j = 0; j < nitems; j++) {
03182                                 float ang = j * 2 * M_PI / nitems;
03183                                 int x0 = (int) floor(cos(ang) * i + cenx);
03184                                 int y0 = (int) floor(sin(ang) * i + ceny);
03185 
03186                                 if (x0 < 0 || y0 < 0 || x0 >= nx || y0 >= ny ||
03187                                         data[x0 + y0 * nx] < thr1 || data[x0 + y0 * nx] > thr2) {
03188                                         continue;
03189                                 }
03190 
03191                                 sum += data[x0 + y0 * nx];
03192                                 square_sum += data[x0 + y0 * nx] * data[x0 + y0 * nx];
03193                                 count++;
03194                         }
03195 
03196                         mean_values[i] = (float) sum / count;
03197                         sigma_values[i] = (float) sqrt(square_sum / count - mean_values[i] * mean_values[i]);
03198                 }
03199         }
03200 
03201         for (int i = 0; i < nx; i++) {
03202                 for (int j = 0; j < ny; j++) {
03203 
03204 #ifdef  _WIN32
03205                         int r = Util::round(_hypot((float) i - cenx, (float) j - ceny));
03206 #else
03207                         int r = Util::round(hypot((float) i - cenx, (float) j - ceny));
03208 #endif  //_WIN32
03209 
03210                         if (value1 < 0) {
03211                                 if (data[i + j * nx] < (mean_values[r] - sigma_values[r] * thr)) {
03212                                         data[i + j * nx] = 0;
03213                                 }
03214                                 else {
03215                                         data[i + j * nx] -= mean_values[r];
03216                                 }
03217                                 continue;
03218                         }
03219                         if (data[i + j * nx] > (mean_values[r] - sigma_values[r] * thr)) {
03220                                 continue;
03221                         }
03222                         data[i + j * nx] = mean_values[r];
03223                 }
03224         }
03225 
03226         if( mean_values )
03227         {
03228                 delete[]mean_values;
03229                 mean_values = 0;
03230         }
03231 
03232         if( sigma_values )
03233         {
03234                 delete[]sigma_values;
03235                 sigma_values = 0;
03236         }
03237 
03238         image->update();
03239 }


Member Data Documentation

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

Definition at line 3860 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:06:57 2010 for EMAN2 by  doxygen 1.4.4