EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::AutoMask3D2Processor Class Reference

Tries to mask out only interesting density. More...

#include <processor.h>

Inheritance diagram for EMAN::AutoMask3D2Processor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::AutoMask3D2Processor:
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 string get_desc () const
 Get the descrition of this specific processor. More...
 
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary. 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.auto3d"
 

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

Tries to mask out only interesting density.

Parameters
radiusPixel radius of a ball which is used to seed the flood filling operation
thresholdAn isosurface threshold that suitably encases the mass
nshellsThe number of dilation operations
nshellsgaussnumber of Gaussian pixels to expand, following the dilation operations @return_mask If true the result of the operation will produce the mask, not the masked volume

Definition at line 6948 of file processor.h.

Member Function Documentation

◆ get_desc()

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

6964 {
6965 return "This will mask a 3-D volume using a 'flood filling' approach. It begins with a seed generated either as a sphere with \
6966specified 'radius' or with the 'nmaxseed' highest values. It then includes any mass connected to the seed with value higher than 'threshold'.\
6967Next, the mask is expanded by 'nshells'+'nshellsgauss'/2 voxels. Finally a gaussian low-pass filter is applied with a width of 'nshellsgauss'.";
6968 }

◆ get_name()

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

6954 {
6955 return NAME;
6956 }
static const string NAME
Definition: processor.h:6984

References NAME.

◆ get_param_types()

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

6971 {
6972 TypeDict d;
6973 d.put("radius", EMObject::INT,"Pixel radius of a ball which is used to seed the flood filling operation. ");
6974 d.put("nmaxseed",EMObject::INT,"Use the n highest valued pixels in the map as a seed. Alternative to radius. Useful for viruses.");
6975 d.put("threshold", EMObject::FLOAT, "An isosurface threshold that suitably encases the mass.");
6976 d.put("sigma", EMObject::FLOAT, "Alternative to threshold based on mean + x*sigma");
6977 d.put("nshells", EMObject::INT, "Number of 1-voxel shells to expand the mask by.");
6978 d.put("nshellsgauss", EMObject::INT, "Width in voxels of a Gaussian decay at the edge of the mask.");
6979 d.put("return_mask", EMObject::BOOL, "If true the result of the operation will produce the mask, not the masked volume.");
6980 d.put("verbose", EMObject::INT, "How verbose to be (stdout)");
6981 return d;
6982 }
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::AutoMask3D2Processor::NEW ( )
inlinestatic

Definition at line 6958 of file processor.h.

6959 {
6960 return new AutoMask3D2Processor();
6961 }
Tries to mask out only interesting density.
Definition: processor.h:6949

◆ process_inplace()

void AutoMask3D2Processor::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 8621 of file processor.cpp.

8622{
8623 if (!image) {
8624 LOGWARN("NULL Image");
8625 return;
8626 }
8627
8628 if (image->get_ndim() != 3) {
8629 throw ImageDimensionException("This processor was only ever designed to work on 3D images.");
8630 }
8631
8632 /*
8633 The mask writing functionality was removed to comply with an EMAN2 policy which dictates that file io is not allowed from within a processor
8634 To get around this just use the return_mask parameter.
8635 string mask_output = params.set_default("write_mask", "");
8636 if ( mask_output != "") {
8637 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.");
8638 if (!EMUtil::is_valid_filename(mask_output)) throw InvalidParameterException("The mask output file name type is invalid or unrecognized");
8639 }
8640 */
8641
8642 int radius=0;
8643 if (params.has_key("radius")) {
8644 radius = params["radius"];
8645 }
8646 int nmaxseed=0;
8647 if (params.has_key("nmaxseed")) {
8648 nmaxseed = params["nmaxseed"];
8649 }
8650
8651 float threshold=0.0;
8652 if (params.has_key("sigma")) threshold=(float)(image->get_attr("mean"))+(float)(image->get_attr("sigma"))*(float)params["sigma"];
8653 else threshold=params["threshold"];
8654
8655 int nshells = params["nshells"];
8656 int nshellsgauss = params["nshellsgauss"];
8657 int verbose=params.set_default("verbose",0);
8658
8659 int nx = image->get_xsize();
8660 int ny = image->get_ysize();
8661 int nz = image->get_zsize();
8662 int nxy=nx*ny;
8663
8664 EMData *amask = new EMData();
8665 amask->set_size(nx, ny, nz);
8666
8667 float *dat = image->get_data();
8668 float *dat2 = amask->get_data();
8669 int i,j,k;
8670 size_t l = 0;
8671
8672 // Seeds with the highest valued pixels
8673 if (nmaxseed>0) {
8674 vector<Pixel> maxs=image->calc_n_highest_locations(nmaxseed);
8675
8676 for (vector<Pixel>::iterator i=maxs.begin(); i<maxs.end(); i++) {
8677 amask->set_value_at((*i).x,(*i).y,(*i).z,1.0);
8678 if (verbose) printf("Seed at %d,%d,%d (%1.3f)\n",(*i).x,(*i).y,(*i).z,(*i).value);
8679 }
8680 }
8681
8682 // Seeds with a sphere
8683 if (radius>0) {
8684 // start with an initial sphere
8685 for (k = -nz / 2; k < nz / 2; ++k) {
8686 for (j = -ny / 2; j < ny / 2; ++j) {
8687 for (i = -nx / 2; i < nx / 2; ++i,++l) {
8688 if (abs(k) > radius || abs(j) > radius || abs(i) > radius) continue;
8689 if ( (k * k + j * j + i * i) > (radius*radius) || dat[l] < threshold) continue;
8690 dat2[l] = 1.0f;
8691 }
8692 }
8693 }
8694 }
8695
8696
8697 // iteratively 'flood fills' the map... recursion would be better
8698 int done=0;
8699 int iter=0;
8700 while (!done) {
8701 iter++;
8702 done=1;
8703 if (verbose && iter%10==0) printf("%d iterations\n",iter);
8704 for (k=1; k<nz-1; ++k) {
8705 for (j=1; j<ny-1; ++j) {
8706 for (i=1; i<nx-1; ++i) {
8707 l=i+j*nx+k*nx*ny;
8708 if (dat2[l]) continue;
8709 if (dat[l]>threshold && (dat2[l-1]||dat2[l+1]||dat2[l+nx]||dat2[l-nx]||dat2[l-nxy]||dat2[l+nxy])) {
8710 dat2[l]=1.0;
8711 done=0;
8712 }
8713 }
8714 }
8715 }
8716 }
8717
8718 amask->update();
8719
8720 if (verbose) printf("expanding mask\n");
8721 amask->process_inplace("mask.addshells.gauss", Dict("val1", (int)(nshells+nshellsgauss/2),"val2",0));
8722 if (verbose) printf("filtering mask\n");
8723 if (nshellsgauss>0) amask->process_inplace("filter.lowpass.gauss", Dict("cutoff_abs", (float)(1.0f/(float)nshellsgauss)));
8724 amask->process_inplace("threshold.belowtozero", Dict("minval",(float)0.002)); // this makes the value exactly 0 beyond ~2.5 sigma
8725
8726 bool return_mask = params.set_default("return_mask",false);
8727 if (return_mask) {
8728 // 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.
8729 dat = image->get_data();
8730 dat2 = amask->get_data();
8731 memcpy(dat,dat2,image->get_size()*sizeof(float));
8732 } else {
8733 image->mult(*amask);
8734 }
8735
8736 // EMAN2 policy is not to allow file io from with a processor
8737 //if (mask_output != "") {
8738 // amask->write_image(mask_output);
8739 //}
8740
8741
8742 delete amask;
8743}
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 AutoMask3D2Processor::NAME = "mask.auto3d"
static

Definition at line 6984 of file processor.h.

Referenced by get_name().


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