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

Thinning a binary map to skelton using the Zhang-Suen thinning algorithm. More...

#include <processor.h>

Inheritance diagram for EMAN::BwThinningProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::BwThinningProcessor:
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...
 
int process_pixel (float *data, float *array, int step)
 
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.thin"
 

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

Thinning a binary map to skelton using the Zhang-Suen thinning algorithm.

(1984, ACM)

Author
: Muyuan Chen
Date
: 03/2015

Definition at line 9538 of file processor.h.

Member Function Documentation

◆ get_desc()

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

9553 {
9554 return "Thinning a binary map to skelton using the Zhang-Suen thinning algorithm.";
9555 }

◆ get_name()

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

9545 {
9546 return NAME;
9547 }
static const string NAME
Definition: processor.h:9566

References NAME.

◆ get_param_types()

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

9558 {
9559 TypeDict d;
9560 d.put("thresh", EMObject::FLOAT, "The threshold to binarize the map.");
9561 d.put("verbose", EMObject::INT, "Verbose");
9562 d.put("preserve_value", EMObject::BOOL, "The value on the skeleton is the same as the original map.");
9563 d.put("ntimes", EMObject::INT, "Number of iterations in the thinning process. Default: -1 (perform thinning until the image is skeltonized");
9564 return d;
9565 }
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::BwThinningProcessor::NEW ( )
inlinestatic

Definition at line 9548 of file processor.h.

9549 {
9550 return new BwThinningProcessor();
9551 }
Thinning a binary map to skelton using the Zhang-Suen thinning algorithm.
Definition: processor.h:9539

◆ process()

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

14652{
14653
14654 EMData* imageCp= image -> copy();
14655 process_inplace(imageCp);
14656
14657 return imageCp;
14658}
virtual void process_inplace(EMData *image)
To process an image in-place.
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
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 BwThinningProcessor::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 14660 of file processor.cpp.

14660 {
14661
14662 int nx = image->get_xsize();
14663 int ny = image->get_ysize();
14664 int nz = image->get_zsize();
14665
14666 float threshold=params.set_default("thresh",0);
14667 int ntimes=params.set_default("ntimes",-1);
14668 int verbose=params.set_default("verbose",0);
14669 int preserve=params.set_default("preserve_value",false);
14670 float array[9];
14671 int n=1;
14672 EMData* imageCp;
14673 if (preserve)
14674 imageCp= image -> copy();
14675 float *data = image->get_data();
14676 size_t total_size = (size_t)nx * (size_t)ny * (size_t)nz;
14677 int nxy = nx * ny;
14678 // binarize image and deal with boundary points first
14679 float *data2 = new float[total_size];
14680 for (int k=0; k<nz; k++){
14681 if (verbose>0)
14682 printf("layer %d \n",k);
14683 size_t knxy = (size_t)k * nxy;
14684 for (int j=0; j<ny; j++){
14685 int jnx = j * nx;
14686 for (int i=0; i<nx; i++){
14687 if(i==0 || i==nx-1 || j==0 || j==ny-1)
14688 data[i+jnx+knxy]=0;
14689 else{
14690 if (data[i+jnx+knxy]>threshold)
14691 data[i+jnx+knxy]=1;
14692 else
14693 data[i+jnx+knxy]=0;
14694 }
14695 }
14696 }
14697
14698 int allt=ntimes;
14699 if (ntimes<0){ // thin to skeleton
14700 allt=65535;
14701 }
14702 // thinning
14703 int cg;
14704 for (int nt=0; nt<allt; nt++){
14705 cg=0;
14706 for (int st = 0; st<2; st++){
14707 memcpy(data2, data, total_size * sizeof(float));
14708 for (int j = n; j < ny - n; j++) {
14709 int jnx = j * nx;
14710 for (int i = n; i < nx - n; i++) {
14711 size_t s = 0;
14712 for (int i2 = i - n; i2 <= i + n; i2++) {
14713 for (int j2 = j - n; j2 <= j + n; j2++) {
14714 array[s] = data2[i2 + j2 * nx+knxy];
14715 ++s;
14716 }
14717 }
14718
14719 cg+=process_pixel(&data[i + jnx+knxy ], array, st);
14720 }
14721 }
14722 }
14723 if (verbose>1)
14724 printf("\t Iter %d, \t %d pixels changed\n",nt,cg);
14725 if(cg==0)
14726 break;
14727 }
14728
14729 // remove corner pixels when doing skeletonization
14730 if (ntimes<0){
14731 cg=0;
14732 memcpy(data2, data, total_size * sizeof(float));
14733 for (int j = n; j < ny - n; j++) {
14734 int jnx = j * nx;
14735 for (int i = n; i < nx - n; i++) {
14736 size_t s = 0;
14737 for (int i2 = i - n; i2 <= i + n; i2++) {
14738 for (int j2 = j - n; j2 <= j + n; j2++) {
14739 array[s] = data2[i2 + j2 * nx+knxy];
14740 ++s;
14741 }
14742 }
14743
14744 cg+=process_pixel(&data[i + jnx+knxy ], array, 2);
14745 }
14746 }
14747 }
14748 if (verbose>1)
14749 printf("\t %d corner pixels\n",cg);
14750 }
14751 image->update();
14752
14753 if( data2 )
14754 {
14755 delete[]data2;
14756 data2 = 0;
14757 }
14758
14759 if (preserve){
14760 image->mult(*imageCp);
14761 delete imageCp;
14762 }
14763
14764}
int process_pixel(float *data, float *array, int step)
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 copy(), EMAN::Processor::params, process_pixel(), and EMAN::Dict::set_default().

Referenced by process().

◆ process_pixel()

int BwThinningProcessor::process_pixel ( float *  data,
float *  array,
int  step 
)

Definition at line 14767 of file processor.cpp.

14767 {
14768
14769 if (*data==0){
14770 return 0;
14771 }
14772 int bp=-1; // number of 1 neighbors, not counting itself
14773 for (int i=0; i<9; i++){
14774 if (array[i]>0)
14775 bp++;
14776 }
14777 if (bp<2 || bp>6){
14778 return 0;
14779 }
14780 int ap=0; // number of transitions from 0 to 1
14781 int order[9]={0,1,2,5,8,7,6,3,0};
14782 for (int i=0; i<8; i++){
14783 if (array[order[i]]==0 && array[order[i+1]]>0){
14784 ap++;
14785 }
14786 }
14787 if (ap!=1 && step<2)
14788 return 0;
14789
14790 if (step==0){
14791 if(array[order[1]]*array[order[3]]*array[order[5]]>0)
14792 return 0;
14793 if(array[order[3]]*array[order[5]]*array[order[7]]>0)
14794 return 0;
14795 }
14796
14797 if (step==1){
14798 if(array[order[1]]*array[order[3]]*array[order[7]]>0)
14799 return 0;
14800 if(array[order[1]]*array[order[5]]*array[order[7]]>0)
14801 return 0;
14802 }
14803
14804 if (step==2){
14805 if (bp==2){
14806 if(array[order[1]]*array[order[3]]>0
14807 || array[order[3]]*array[order[5]]>0
14808 || array[order[5]]*array[order[7]]>0
14809 || array[order[7]]*array[order[1]]>0
14810 ){
14811 *data=0;
14812 return 1;
14813 }
14814 else{
14815 return 0;
14816 }
14817 }
14818 if (ap==2 ){
14819 if(array[order[1]]*array[order[3]]>0
14820 || array[order[3]]*array[order[5]]>0
14821 ){
14822 *data=0;
14823 return 1;
14824 }
14825 else{
14826 return 0;
14827 }
14828 }
14829 return 0;
14830 }
14831
14832 *data=0;
14833 return 1;
14834
14835}

Referenced by process_inplace().

Member Data Documentation

◆ NAME

const string BwThinningProcessor::NAME = "morph.thin"
static

Definition at line 9566 of file processor.h.

Referenced by get_name().


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