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

Label each object in a black-white image. More...

#include <processor.h>

Inheritance diagram for EMAN::ObjLabelProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::ObjLabelProcessor:
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.object.label"
 

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

Label each object in a black-white image.

Also return the center of each object.

Author
: Muyuan Chen
Date
: 03/2015

Definition at line 9507 of file processor.h.

Member Function Documentation

◆ get_desc()

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

9522 {
9523 return "Label each object above threshold. Also return the center of each object. Treats a 3D volume as 2D slices.";
9524 }

◆ get_name()

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

9514 {
9515 return NAME;
9516 }
static const string NAME
Definition: processor.h:9531

References NAME.

◆ get_param_types()

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

9526 {
9527 TypeDict d;
9528 d.put("write_centers", EMObject::BOOL, "Write the center of each object in the attribute obj_centers.");
9529 return d;
9530 }
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, and EMAN::TypeDict::put().

◆ NEW()

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

Definition at line 9517 of file processor.h.

9518 {
9519 return new ObjLabelProcessor();
9520 }
Label each object in a black-white image.
Definition: processor.h:9508

◆ process()

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

14558{
14559
14560 EMData* imageCp= image -> copy();
14561 process_inplace(imageCp);
14562
14563 return imageCp;
14564}
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 ObjLabelProcessor::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 14566 of file processor.cpp.

14567{
14568 // Now treats 3d volume as 2d slices
14569 bool writecenter=params.set_default("write_centers",false);
14570 int nx = image->get_xsize();
14571 int ny = image->get_ysize();
14572 int nz = image->get_zsize();
14573
14574 int y1;
14575 bool spanLeft, spanRight;
14576 vector<Vec3i> pvec;
14577 float cx,cy;
14578 int npx;
14579 int count=0;
14580 vector<float> centers(2);
14581 for (int zz = 0; zz < nz; zz++) {
14582
14583 for (int yy = 0; yy < ny; yy++) {
14584 for (int xx = 0; xx < nx; xx++) {
14585 if (image->get_value_at(xx,yy,zz)>0){
14586 pvec.push_back(Vec3i(xx,yy,zz));
14587 if (writecenter && count<0){
14588 cx/=npx;cy/=npx;
14589 centers.push_back(cx);
14590 centers.push_back(cy);
14591 cx=cy=0;npx=0;
14592 }
14593 count--;
14594 }
14595 while(!pvec.empty())
14596 {
14597 Vec3i v=pvec.back();
14598 int x=v[0],y=v[1],z=v[2];
14599// printf("%d\t%d\t%d\n",x,y,z);
14600 pvec.pop_back();
14601 y1 = y;
14602 while(y1 > 0 && image->get_value_at(x,y1,zz)>0) y1--;
14603// y1++;
14604 spanLeft = spanRight = 0;
14605 bool nowstop=0;
14606 while(1)
14607 {
14608 if(image->get_value_at(x,y1,zz)>0){
14609 image->set_value_at(x,y1,zz,count);
14610 if (writecenter){
14611 cx+=x;cy+=y1;npx++;
14612 }
14613 }
14614
14615// printf("\t %d\t%d\t%d\n",x,y1,z);
14616 if(!spanLeft && x > 0 && image->get_value_at(x-1,y1,zz)>0)
14617 {
14618 pvec.push_back(Vec3i(x-1,y1,zz));
14619 spanLeft = 1;
14620 }
14621 else if(spanLeft && x > 0 && image->get_value_at(x-1,y1,zz)<=0)
14622 {
14623 spanLeft = 0;
14624 }
14625 if(!spanRight && x < nx - 1 && image->get_value_at(x+1,y1,zz)>0)
14626 {
14627 pvec.push_back(Vec3i(x+1,y1,zz));
14628 spanRight = 1;
14629 }
14630 else if(spanRight && x < nx - 1 && image->get_value_at(x+1,y1,zz)<=0)
14631 {
14632 spanRight = 0;
14633 }
14634 y1++;
14635 if (nowstop)
14636 break;
14637 if (y1 >= ny-1 || image->get_value_at(x,y1,zz)<=0)
14638 nowstop=1;
14639 }
14640 }
14641
14642
14643 }
14644 }
14645 }
14646 printf("%d objects.\n",-count);
14647 image->mult(-1);
14648 if (writecenter) image->set_attr("obj_centers",centers);
14649}
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
float get_value_at(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
Definition: emdata_core.h:221
Vec3< int > Vec3i
Definition: vec3.h:694
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

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

Referenced by process().

Member Data Documentation

◆ NAME

const string ObjLabelProcessor::NAME = "morph.object.label"
static

Definition at line 9531 of file processor.h.

Referenced by get_name().


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