EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
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]

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
 
virtual string get_desc () const
 Get the descrition of this specific processor. More...
 
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
 
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...
 

Static Public Member Functions

static ProcessorNEW ()
 
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
 
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
 
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...
 

Static Public Attributes

static const string NAME = "mask.auto2d"
 

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
  TOP_HAT_LOW_PASS , TOP_HAT_HIGH_PASS , TOP_HAT_BAND_PASS , TOP_HOMOMORPHIC ,
  GAUSS_LOW_PASS , GAUSS_HIGH_PASS , GAUSS_BAND_PASS , GAUSS_INVERSE ,
  GAUSS_HOMOMORPHIC , BUTTERWORTH_LOW_PASS , BUTTERWORTH_HIGH_PASS , BUTTERWORTH_HOMOMORPHIC ,
  KAISER_I0 , KAISER_SINH , KAISER_I0_INVERSE , KAISER_SINH_INVERSE ,
  SHIFT , TANH_LOW_PASS , TANH_HIGH_PASS , TANH_HOMOMORPHIC ,
  TANH_BAND_PASS , RADIAL_TABLE , CTF_
}
 Fourier filter Processor type enum. More...
 
- Protected Attributes inherited from EMAN::Processor
Dict params
 

Detailed Description

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

Parameters
thresholdruns from ~ -2 to 2, negative numbers for dark protein and positive numbers for light protein (stain).
filteris expressed as a fraction of the fourier radius.

Definition at line 6786 of file processor.h.

Member Function Documentation

◆ get_desc()

virtual string EMAN::AutoMask2DProcessor::get_desc ( ) const
inlinevirtual

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

6816 {
6817 return "2D version of mask.auto3d";
6818 }

◆ get_name()

virtual string EMAN::AutoMask2DProcessor::get_name ( ) const
inlinevirtual

Get the processor's name.

Each processor is identified by a unique name.

Returns
The processor's name.

Implements EMAN::Processor.

Definition at line 6791 of file processor.h.

6792 {
6793 return NAME;
6794 }
static const string NAME
Definition: processor.h:6820

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::AutoMask2DProcessor::get_param_types ( ) const
inlinevirtual

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

6802 {
6803 TypeDict d;
6804 d.put("radius", EMObject::INT,"Pixel radius of a ball which is used to seed the flood filling operation. ");
6805 d.put("nmaxseed",EMObject::INT,"Use the n highest valued pixels in the map as a seed. Alternative to radius. Useful for viruses.");
6806 d.put("threshold", EMObject::FLOAT, "An isosurface threshold that suitably encases the mass.");
6807 d.put("sigma", EMObject::FLOAT, "Alternative to threshold based on mean + x*sigma");
6808 d.put("nshells", EMObject::INT, "The number of dilation operations");
6809 d.put("nshellsgauss", EMObject::INT, "number of Gaussian pixels to expand, following the dilation operations");
6810 d.put("return_mask", EMObject::BOOL, "If true the result of the operation will produce the mask, not the masked volume.");
6811 d.put("verbose", EMObject::INT, "How verbose to be (stdout)");
6812 return d;
6813 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

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

◆ NEW()

static Processor * EMAN::AutoMask2DProcessor::NEW ( )
inlinestatic

Definition at line 6796 of file processor.h.

6797 {
6798 return new AutoMask2DProcessor();
6799 }
Attempts to automatically mask out the particle, excluding other particles in the box,...
Definition: processor.h:6787

◆ process_inplace()

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
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 6757 of file processor.cpp.

6758{
6759 if (!image) {
6760 LOGWARN("NULL Image");
6761 return;
6762 }
6763
6764 if (image->get_ndim() != 2) {
6765 throw ImageDimensionException("This processor only supports 2D images.");
6766 }
6767
6768 /*
6769 The mask writing functionality was removed to comply with an EMAN2 policy which dictates that file io is not allowed from within a processor
6770 To get around this just use the return_mask parameter.
6771 string mask_output = params.set_default("write_mask", "");
6772 if ( mask_output != "") {
6773 if (Util::is_file_exist(mask_output) ) throw InvalidParameterException("The mask output file name already exists. Please remove it if you don't need it.");
6774 if (!EMUtil::is_valid_filename(mask_output)) throw InvalidParameterException("The mask output file name type is invalid or unrecognized");
6775 }
6776 */
6777
6778 int radius=params.set_default("radius",0);
6779 int nmaxseed=params.set_default("nmaxseed",0);
6780
6781 float threshold=0.0;
6782 if (params.has_key("sigma") || !params.has_key("threshold")) threshold=(float)(image->get_attr("mean"))+(float)(image->get_attr("sigma"))*(float)params["sigma"];
6783 else threshold=params["threshold"];
6784
6785
6786 int nshells = params.set_default("nshells",0);
6787 int nshellsgauss = params.set_default("nshellsgauss",0);
6788 int verbose=params.set_default("verbose",0);
6789
6790 int nx = image->get_xsize();
6791 int ny = image->get_ysize();
6792
6793 EMData *amask = new EMData();
6794 amask->set_size(nx, ny);
6795
6796 float *dat = image->get_data();
6797 float *dat2 = amask->get_data();
6798 int i,j;
6799 size_t l = 0;
6800
6801 if (verbose) printf("%f\t%f\t%f\t%d\n",(float)image->get_attr("mean"),(float)image->get_attr("sigma"),threshold,nmaxseed);
6802
6803 // Seeds with the highest valued pixels
6804 if (nmaxseed>0) {
6805 EMData *peaks=image->process("mask.onlypeaks",Dict("npeaks",0)); // only find true peak values (pixels surrounded by lower values)
6806 vector<Pixel> maxs=peaks->calc_n_highest_locations(nmaxseed);
6807 delete peaks;
6808
6809 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
6810 if ((*i).x==0 || (*i).y==0 ) continue; // generally indicates a failed peak search, and regardless we don't really want edges
6811 amask->set_value_at((*i).x,(*i).y,0,1.0);
6812 if (verbose) printf("Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
6813 }
6814 }
6815
6816 // Seeds with a circle
6817 if (radius>0) {
6818 // start with an initial circle
6819 l=0;
6820 for (j = -ny / 2; j < ny / 2; ++j) {
6821 for (i = -nx / 2; i < nx / 2; ++i,++l) {
6822 if ( abs(j) > radius || abs(i) > radius) continue;
6823 if ( (j * j + i * i) > (radius*radius) || dat[l] < threshold) continue; // torn on the whole threshold issue here. Removing it prevents images from being totally masked out
6824 if ( (j * j + i * i) > (radius*radius) ) continue;
6825 dat2[l] = 1.0f;
6826 }
6827 }
6828 }
6829
6830 // iteratively 'flood fills' the map... recursion would be better
6831 int done=0;
6832 int iter=0;
6833 while (!done) {
6834 iter++;
6835 done=1;
6836 if (verbose && iter%10==0) printf("%d iterations\n",iter);
6837 for (j=1; j<ny-1; ++j) {
6838 for (i=1; i<nx-1; ++i) {
6839 l=i+j*nx;
6840 if (dat2[l]) continue;
6841 if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx])) {
6842 dat2[l]=1.0;
6843 done=0;
6844 }
6845 }
6846 }
6847 }
6848
6849 amask->update();
6850
6851 if (verbose) printf("extending mask\n");
6852 if (nshells>0 || nshellsgauss>0) amask->process_inplace("mask.addshells.gauss", Dict("val1", nshells, "val2", nshellsgauss));
6853
6854 bool return_mask = params.set_default("return_mask",false);
6855 if (return_mask) {
6856 // Yes there is probably a much more efficient way of getting the mask itself, but I am only providing a stop gap at the moment.
6857 memcpy(dat,dat2,image->get_size()*sizeof(float));
6858 } else {
6859 image->mult(*amask);
6860 }
6861
6862 // EMAN2 policy is not to allow file io from with a processor
6863 //if (mask_output != "") {
6864 // amask->write_image(mask_output);
6865 //}
6866
6867
6868 delete amask;
6869}
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
#define ImageDimensionException(desc)
Definition: exception.h:166
#define LOGWARN
Definition: log.h:53

References EMAN::Dict::has_key(), ImageDimensionException, LOGWARN, EMAN::Processor::params, and EMAN::Dict::set_default().

Member Data Documentation

◆ NAME

const string AutoMask2DProcessor::NAME = "mask.auto2d"
static

Definition at line 6820 of file processor.h.

Referenced by get_name().


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