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

Prune branches from the skeleton. More...

#include <processor.h>

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

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place. More...
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
virtual string get_name () const
 Get the processor's name. More...
 
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 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 = "morph.prune"
 

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

Prune branches from the skeleton.

Remove a piece when the minimum distance through density from an endpoint to the nearest branch point is shorter than a given value.

Author
: Muyuan Chen
Date
: 04/2015

Definition at line 9623 of file processor.h.

Member Function Documentation

◆ get_desc()

string EMAN::PruneSkeletonProcessor::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 9637 of file processor.h.

9638 {
9639 return "Prune branches from the skeleton. Remove a piece when the minimum distance through density from an endpoint to the nearest branch point is shorter than a given value.";
9640 }

◆ get_name()

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

9630 {
9631 return NAME;
9632 }
static const string NAME
Definition: processor.h:9650

References NAME.

◆ get_param_types()

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

9642 {
9643 TypeDict d;
9644 d.put("thresh", EMObject::FLOAT, "The threshold to binarize the map.");
9645 d.put("verbose", EMObject::INT, "Verbose");
9646 d.put("returnlength", EMObject::BOOL, "Return the distance of each white pixel to its nearest branch. Does not do the prunning.");
9647 d.put("maxdist", EMObject::INT, "Maximum distance from the endpoint to branchpoint");
9648 return d;
9649 }
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::PruneSkeletonProcessor::NEW ( )
inlinestatic

Definition at line 9633 of file processor.h.

9634 {
9635 return new PruneSkeletonProcessor();
9636 }
Prune branches from the skeleton.
Definition: processor.h:9624

◆ process()

EMData * PruneSkeletonProcessor::process ( const EMData *const  image)
virtual

To proccess an image out-of-place.

For those processors which can only be processed out-of-place, override this function to give the right behavior.

Parameters
imageThe image will be copied, actual process happen on copy of image.
Returns
the image processing result, may or may not be the same size of the input image

Reimplemented from EMAN::Processor.

Definition at line 14837 of file processor.cpp.

14838{
14839 EMData* imageCp= image -> copy();
14840 process_inplace(imageCp);
14841 return imageCp;
14842}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
virtual void process_inplace(EMData *image)
To process an image in-place.
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....

References copy(), and process_inplace().

◆ process_inplace()

void PruneSkeletonProcessor::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 14844 of file processor.cpp.

14844 {
14845 // This function is far from optimized, but it works...
14846
14847 int nx = image->get_xsize();
14848 int ny = image->get_ysize();
14849 int nz = image->get_zsize();
14850
14851 float threshold=params.set_default("thresh",0);
14852 int verbose=params.set_default("verbose",0);
14853 int maxdist=params.set_default("maxdist",3);
14854 bool returnlength=params.set_default("returnlength",false);
14855/*
14856 if (nz > 1) {
14857 ImageDimensionException("Only 2-D images supported");
14858 }*/
14859
14860 float *data = image->get_data();
14861 size_t total_size = (size_t)nx * (size_t)ny * (size_t)nz;
14862
14863 float *data2 = new float[total_size];
14864 memcpy(data2, data, total_size * sizeof(float));
14865 int nxy = nx * ny;
14866 // binarize image and deal with boundary points first
14867 for (int k=0; k<nz; k++){
14868 if (verbose>0)
14869 printf("layer %d \n",k);
14870 size_t knxy = (size_t)k * nxy;
14871 // binarize image first
14872 for (int j=0; j<ny; j++){
14873 int jnx = j * nx;
14874 for (int i=0; i<nx; i++){
14875
14876 if (data[knxy+i+jnx]>threshold)
14877 data[knxy+i+jnx]=1;
14878 else
14879 data[knxy+i+jnx]=0;
14880 }
14881 }
14882
14883 float array[9];
14884 image->to_zero();
14885
14886 // find branch points
14887 int nbranch=0;
14888 for (int j=1; j < ny-1; j++) {
14889 int jnx = j * nx;
14890 for (int i=1; i<nx-1; i++) {
14891
14892 if (data2[knxy+i+jnx]<=threshold)
14893 continue;
14894 int s=0;
14895 for (int i2 = i-1; i2 <= i + 1; i2++) {
14896 for (int j2 = j - 1; j2 <= j + 1; j2++) {
14897 array[s++] = data2[knxy+i2 + j2 * nx];
14898 }
14899 }
14900 int ap=0; // number of transitions from 0 to 1
14901 int order[9]={0,1,2,5,8,7,6,3,0};
14902 for (int oi=0; oi<8; oi++){
14903 if (array[order[oi]]<=threshold && array[order[oi+1]]>threshold){
14904 ap++;
14905 }
14906 }
14907 if (ap>2){
14908 data[knxy+i+jnx]=1;
14909 nbranch++;
14910 }
14911 }
14912 }
14913 if (verbose>0)
14914 printf("\t %d branch pixels\n",nbranch);
14915
14916 // now, data->branch points, data2->binarized image
14917
14918 // distance to branch point
14919 for (int j=1; j<ny; j++){
14920 int jnx=j*nx;
14921 for (int i=0; i<nx; i++){
14922 data[knxy+i+jnx]=(1-data[knxy+i+jnx])*(maxdist+1);
14923 }
14924
14925 }
14926 for (int dt=0; dt<maxdist; dt++){
14927 for (int j=1; j < ny-1; j++) {
14928 int jnx=j*nx;
14929 for (int i=1; i<nx-1; i++) {
14930
14931 if (data2[knxy+i+jnx]<=threshold)
14932 continue;
14933 if (data[knxy+i+jnx]<=maxdist)
14934 continue;
14935 int db=maxdist; // distance from nearest branch point.
14936 for (int i2=i-1; i2<=i+1; i2++) {
14937 for (int j2=j-1; j2<=j+1; j2++) {
14938 db=(data[knxy+i2+j2*nx]==dt ? dt : db);
14939 }
14940 }
14941 data[knxy+i+jnx]=db+1;
14942 }
14943 }
14944 }
14945 // now, data->distance to the nearest branch point
14946
14947 if (returnlength==false){
14948 // mark endpoints for deletion
14949 int nend=0;
14950 for (int j=1; j < ny-1; j++) {
14951 int jnx=j*nx;
14952 for (int i=1; i<nx-1; i++) {
14953
14954 if (data2[knxy+i+jnx]<=threshold)
14955 continue;
14956 if (data[knxy+i+jnx]>maxdist)
14957 continue;
14958 int nb=-1; // number of neighbors
14959 for (int i2=i-1; i2<=i+1; i2++) {
14960 for (int j2=j-1; j2<=j+1; j2++) {
14961 nb+=(data2[knxy+i2+j2*nx]>threshold ? 1 : 0);
14962 }
14963 }
14964 if (nb==1){ // endpoint found
14965 data[knxy+i+jnx]=-data[knxy+i+jnx]; //mark for deletion
14966 data2[knxy+i+jnx]=threshold;
14967 nend++;
14968 }
14969 }
14970 }
14971
14972 // remove marked branches
14973 for (int dt=-maxdist; dt<-1; dt++){
14974 for (int j=1; j < ny-1; j++) {
14975 int jnx=j*nx;
14976 for (int i=1; i<nx-1; i++) {
14977
14978 if (data2[knxy+i+jnx]<=threshold)
14979 continue;
14980 if (data[knxy+i+jnx]<=0)
14981 continue;
14982 int rm=0; // delete this pixel
14983 for (int i2=i-1; i2<=i+1; i2++) {
14984 for (int j2=j-1; j2<=j+1; j2++) {
14985 rm=( data[knxy+i2+j2*nx]==dt ? 1 : rm );
14986 }
14987 }
14988 if (rm>0){
14989 data2[knxy+i+jnx]=threshold;
14990 data[knxy+i+jnx]=dt+1;
14991 }
14992 }
14993 }
14994 }
14995 if (verbose>0)
14996 printf("\t %d branches removed\n",nend);
14997 }
14998 }
14999 if (returnlength==false){
15000 memcpy(data, data2, total_size * sizeof(float));
15001 }
15002
15003
15004 image->update();
15005 if( data2 )
15006 {
15007 delete[]data2;
15008 data2 = 0;
15009 }
15010
15011}
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

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

Referenced by process().

Member Data Documentation

◆ NAME

const string PruneSkeletonProcessor::NAME = "morph.prune"
static

Definition at line 9650 of file processor.h.

Referenced by get_name().


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