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

03841                 {
03842                         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.";
03843                 }

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

03831                 {
03832                         return NAME;
03833                 }

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

References EMAN::TypeDict::put().

03846                 {
03847                         TypeDict d;
03848                         d.put("value1", EMObject::FLOAT, "sig multiplier");
03849                         d.put("value2", EMObject::FLOAT, "x of center");
03850                         d.put("value3", EMObject::FLOAT, "y of center");
03851                         return d;
03852                 }

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

Definition at line 3835 of file processor.h.

03836                 {
03837                         return new BeamstopProcessor();
03838                 }

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

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


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 Thu Nov 17 12:46:15 2011 for EMAN2 by  doxygen 1.3.9.1