EMAN::AutoMask2DProcessor Class Reference

Attempts to automatically mask out the particle, excluding other particles in the box, etc. More...

#include <processor.h>

Inheritance diagram for EMAN::AutoMask2DProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::AutoMask2DProcessor:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place.
virtual string get_name () const
 Get the processor's name.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
virtual string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()


Detailed Description

Attempts to automatically mask out the particle, excluding other particles in the box, etc.

Parameters:
threshold runs from ~ -2 to 2, negative numbers for dark protein and positive numbers for light protein (stain).
filter is expressed as a fraction of the fourier radius.

Definition at line 4558 of file processor.h.


Member Function Documentation

void AutoMask2DProcessor::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 4773 of file processor.cpp.

References EMAN::EMData::copy(), EMAN::Dict::get(), EMAN::EMData::get_attr_dict(), EMAN::EMData::get_data(), EMAN::Util::get_max(), EMAN::Util::get_min(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, LOGERR, LOGWARN, EMAN::EMData::mult(), EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::EMData::update(), and v.

04774 {
04775         if (!image) {
04776                 LOGWARN("NULL Image");
04777                 return;
04778         }
04779 
04780         int nz = image->get_zsize();
04781         if (nz > 1) {
04782                 LOGERR("%s Processor doesn't support 3D model", get_name().c_str());
04783                 throw ImageDimensionException("3D model not supported");
04784         }
04785 
04786         float threshold = params["threshold"];
04787         float filter = 0.1f;
04788         if (params.has_key("filter")) {
04789                 filter = params["filter"];
04790         }
04791 
04792         EMData *d = image->copy();
04793 
04794         if (threshold > 0) {
04795                 threshold = -threshold;
04796                 d->mult(-1);
04797         }
04798 
04799         int ny = image->get_ysize();
04800 
04801         d->process_inplace("eman1.filter.lowpass.gaussian", Dict("lowpass", (filter * ny / 2)));
04802         d->process_inplace("eman1.filter.highpass.gaussian", Dict("highpass", 0));
04803 
04804         d->process_inplace("normalize");
04805 
04806         int d_nx = d->get_xsize();
04807         int d_ny = d->get_ysize();
04808         int d_size = d_nx * d_ny;
04809 
04810         float *dn = (float *) calloc(d_size, sizeof(float));
04811         float *dc = (float *) calloc(d_size, sizeof(float));
04812         float *dd = d->get_data();
04813 
04814         int k = 0;
04815         const float dn_const = 10;
04816         float d_sigma = d->get_attr_dict().get("sigma");
04817         float threshold_sigma = threshold * d_sigma;
04818 
04819         for (int l = 0; l < d_ny; l++) {
04820                 for (int j = 0; j < d_nx; j++) {
04821 #ifdef  _WIN32
04822                         if (_hypot(l - d_ny / 2, j - d_nx / 2) >= d_ny / 2) {
04823 #else
04824                         if (hypot(l - d_ny / 2, j - d_nx / 2) >= d_ny / 2) {
04825 #endif
04826                                 dn[k] = -dn_const;
04827                         }
04828                         else if (dd[k] < threshold_sigma) {
04829                                 dn[k] = dn_const;
04830                         }
04831                         else {
04832                                 dn[k] = 0;
04833                         }
04834                         k++;
04835                 }
04836         }
04837 
04838         int ch = 1;
04839         while (ch) {
04840                 ch = 0;
04841                 memcpy(dc, dn, d_size * sizeof(float));
04842 
04843                 for (int l = 1; l < d_ny - 1; l++) {
04844                         for (int j = 1; j < d_nx - 1; j++) {
04845                                 k = j + l * d_nx;
04846                                 if (dn[k] == dn_const) {
04847                                         if (dn[k - 1] == -dn_const || dn[k + 1] == -dn_const ||
04848                                                 dn[k - d_nx] == -dn_const || dn[k + d_nx] == -dn_const) {
04849                                                 dn[k] = -dn_const;
04850                                                 ch = 1;
04851                                         }
04852                                 }
04853                         }
04854                 }
04855         }
04856 
04857         k = 0;
04858         float threshold_sigma2 = threshold * d_sigma * 2;
04859 
04860         for (int l = 0; l < d_ny; l++) {
04861                 for (int j = 0; j < d_nx; j++) {
04862                         if (l == 0 || l == d_ny - 1 || j == 0 || j == d_nx - 1) {
04863                                 dn[k] = -dn_const;
04864                         }
04865                         else if (dd[k] > threshold_sigma2 && dn[k] == dn_const) {
04866                                 dn[k] = 0;
04867                         }
04868                         k++;
04869                 }
04870         }
04871 
04872         ch = 1;
04873         const float v_const = 0.25f;
04874 
04875         while (ch) {
04876                 ch = 0;
04877                 memcpy(dc, dn, d_size * sizeof(float));
04878 
04879                 for (int l = 1; l < d_ny - 1; l++) {
04880                         for (int j = 1; j < d_nx - 1; j++) {
04881                                 int k = j + l * d_nx;
04882 
04883                                 if (dn[k] != -dn_const && dn[k] != dn_const) {
04884                                         float v = Util::get_max(dc[k - 1], dc[k + 1], dc[k - d_nx], dc[k + d_nx]);
04885                                         float v2 = Util::get_min(dc[k - 1], dc[k + 1], dc[k - d_nx], dc[k + d_nx]);
04886 
04887                                         if (v2 >= 0 && v > v_const) {
04888                                                 dn[k] = v - v_const;
04889                                         }
04890                                         else if (v <= 0 && v2 < -v_const) {
04891                                                 dn[k] = v2 + v_const;
04892                                         }
04893                                         else if (v > .25f && v2 < -v_const) {
04894                                                 dn[k] = (v + v2) / 2;
04895                                         }
04896                                         if (dn[k] != dc[k]) {
04897                                                 ch++;
04898                                         }
04899                                 }
04900                         }
04901                 }
04902         }
04903 
04904         for (int k = 0; k < d_size; k++) {
04905                 if (dn[k] >= -5) {
04906                         dn[k] = 1;
04907                 }
04908                 else {
04909                         dn[k] = 0;
04910                 }
04911         }
04912 
04913         dn[d_nx * d_ny / 2 + d_nx / 2] = 2;
04914         ch = 1;
04915         while (ch) {
04916                 ch = 0;
04917                 for (int l = 1; l < d_ny - 1; l++) {
04918                         for (int j = 1; j < d_nx - 1; j++) {
04919                                 int k = j + l * d_nx;
04920                                 if (dn[k] == 1) {
04921                                         float v = Util::get_max(dn[k - 1], dn[k + 1], dn[k - d_nx], dn[k + d_nx]);
04922                                         if (v == 2.0f) {
04923                                                 dn[k] = 2.0f;
04924                                                 ch = 1;
04925                                         }
04926                                 }
04927                         }
04928                 }
04929         }
04930 
04931         for (ch = 0; ch < 4; ch++) {
04932                 memcpy(dc, dn, d_nx * d_ny * sizeof(float));
04933 
04934                 for (int l = 1; l < d_ny - 1; l++) {
04935                         for (int j = 1; j < d_nx - 1; j++) {
04936                                 int k = j + l * d_nx;
04937 
04938                                 if (dc[k] != 2.0f) {
04939                                         float v = Util::get_max(dc[k - 1], dc[k + 1], dc[k - d_nx], dc[k + d_nx]);
04940                                         if (v == 2.0f) {
04941                                                 dn[k] = 2.0f;
04942                                         }
04943                                 }
04944                         }
04945                 }
04946         }
04947 
04948         for (int k = 0; k < d_size; k++) {
04949                 if (dn[k] == 2.0f) {
04950                         dn[k] = 1;
04951                 }
04952                 else {
04953                         dn[k] = 0;
04954                 }
04955         }
04956 
04957         memcpy(dd, dn, d_size * sizeof(float));
04958         if( dn )
04959         {
04960                 free(dn);
04961                 dn = 0;
04962         }
04963 
04964         if( dc )
04965         {
04966                 free(dc);
04967                 dc = 0;
04968         }
04969 
04970         d->update();
04971 
04972         image->mult(*d);
04973         if( d )
04974         {
04975                 delete d;
04976                 d = 0;
04977         }
04978 }

virtual string EMAN::AutoMask2DProcessor::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 4563 of file processor.h.

Referenced by process_inplace().

04564                 {
04565                         return "mask.auto2d";
04566                 }

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

Definition at line 4568 of file processor.h.

04569                 {
04570                         return new AutoMask2DProcessor();
04571                 }

virtual TypeDict EMAN::AutoMask2DProcessor::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 4573 of file processor.h.

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

04574                 {
04575                         TypeDict d;
04576                         d.put("threshold", EMObject::FLOAT, "runs from ~ -2 to 2, negative numbers for dark protein and positive numbers for light protein (stain).");
04577                         d.put("filter", EMObject::FLOAT, "is expressed as a fraction of the fourier radius.");
04578                         return d;
04579                 }

virtual string EMAN::AutoMask2DProcessor::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 4581 of file processor.h.

04582                 {
04583                         return "Attempts to automatically mask out the particle, excluding other particles in the box, etc.";
04584                 }


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:34 2009 for EMAN2 by  doxygen 1.5.6