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

Sets pixel values in a binary image equal to their element wise manhattan distance. More...

#include <processor.h>

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

Public Member Functions

 ManhattanDistanceProcessor ()
 
string get_name () const
 Get the processor's name. More...
 
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
 
void process_inplace (EMData *image)
 To process an image in-place. More...
 
string get_desc () const
 Get the descrition of this specific processor. More...
 
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 = "math.distance.manhattan"
 

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

Sets pixel values in a binary image equal to their element wise manhattan distance.

Credit for this code goes to Stephen Ostermiller (http://blog.ostermiller.org/dilate-and-erode).

Author
James Michael Bell
Date
06/27/2015

Definition at line 1193 of file processor.h.

Constructor & Destructor Documentation

◆ ManhattanDistanceProcessor()

EMAN::ManhattanDistanceProcessor::ManhattanDistanceProcessor ( )
inline

Definition at line 1196 of file processor.h.

1196{}

Referenced by NEW().

Member Function Documentation

◆ get_desc()

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

1213 {
1214 return "Sets pixel values in a binary image equal to their element wise manhattan distance.";
1215 }

◆ get_name()

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

1199 {
1200 return NAME;
1201 }
static const string NAME
Definition: processor.h:1224

References NAME.

◆ get_param_types()

TypeDict EMAN::ManhattanDistanceProcessor::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 1217 of file processor.h.

1218 {
1219 TypeDict d;
1220 //d.put("threshold", EMObject::FLOAT,"Only considers densities above the threshold");
1221 return d;
1222 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305

◆ NEW()

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

Definition at line 1207 of file processor.h.

1208 {
1209 return new ManhattanDistanceProcessor();
1210 }

References ManhattanDistanceProcessor().

◆ process()

EMData * ManhattanDistanceProcessor::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 15098 of file processor.cpp.

15099{
15100 EMData* proc = image->copy();
15101 proc->process_inplace("math.distance.manhattan");
15102 return proc;
15103}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82

◆ process_inplace()

void ManhattanDistanceProcessor::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 15105 of file processor.cpp.

15106{
15107 if (!image) {
15108 LOGWARN("NULL Image");
15109 return;
15110 }
15111
15112 int nx = image->get_xsize();
15113 int ny = image->get_ysize();
15114 int nz = image->get_zsize();
15115 int size = nx*ny*nz;
15116
15117 // traverse from top left to bottom right
15118 for (int i=0; i<nx; i++) {
15119 for (int j=0; j<ny; j++) {
15120 for (int k=0; k<nz; k++) {
15121 if (image->get_value_at(i,j,k) == 1) {
15122 image->set_value_at_fast(i,j,k,0); // first pass and pixel was on, it gets a zero
15123 } else {
15124 image->set_value_at_fast(i,j,k,size+nx); // pixel was off. It is at most the sum of the lengths of the array away from a pixel that is on...
15125 float north = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i-1,j,k)+1);
15126 float west = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j-1,k)+1);
15127 float above = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j,k-1)+1);
15128 if (i>0) image->set_value_at_fast(i,j,k,north); // or one more than the pixel to the north
15129 if (j>0) image->set_value_at_fast(i,j,k,west); // or one more than the pixel to the west
15130 if (k>0) image->set_value_at_fast(i,j,k,above); // or one more than the pixel above
15131 }
15132 }
15133 }
15134 }
15135
15136 // traverse from bottom right to top left. Pixels will either be what we had on the first pass...
15137 for (int i=nx-2; i>=0; i--) {
15138 for (int j=ny-2; j>=0; j--) {
15139 for (int k=nz-2; k>=0; k--) {
15140 if (image->get_value_at(i,j,k) == 1) {
15141 image->set_value_at_fast(i,j,k,0); // first pass and pixel was on, it gets a zero
15142 } else {
15143 float south = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i+1,j,k)+1);
15144 float east = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j+1,k)+1);
15145 float below = Util::get_min(image->get_value_at(i,j,k),image->get_value_at(i,j,k+1)+1);
15146 if (i+1<nx) image->set_value_at_fast(i,j,k,south); // or one more than the pixel to the south
15147 if (j+1<ny) image->set_value_at_fast(i,j,k,east); // or one more than the pixel to the east
15148 if (k+1<nz) image->set_value_at_fast(i,j,k,below); // or one more than the pixel below
15149 }
15150 }
15151 }
15152 }
15153}
static int get_min(int f1, int f2)
Get the minimum of 2 numbers.
Definition: util.h:922
#define LOGWARN
Definition: log.h:53

References EMAN::Util::get_min(), and LOGWARN.

Member Data Documentation

◆ NAME

const string ManhattanDistanceProcessor::NAME = "math.distance.manhattan"
static

Definition at line 1224 of file processor.h.

Referenced by get_name().


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