EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::DistanceSegmentProcessor Class Reference

Segment a volume about:homeinto subvolumes based on a center separation value. More...

#include <processor.h>

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

List of all members.

Public Member Functions

string get_name () const
 Get the processor's name.
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place.
void process_inplace (EMData *image)
 To process an image in-place.
TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "segment.distance"

Detailed Description

Segment a volume about:homeinto subvolumes based on a center separation value.

For linear densities such as skeletons this should fill linear regions with uniformly separated points

Author:
Steve Ludtke
Date:
2010/07/14

Definition at line 747 of file processor.h.


Member Function Documentation

string EMAN::DistanceSegmentProcessor::get_desc ( ) const [inline, virtual]

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 773 of file processor.h.

                {
                        return "Segments a volume into pieces separated by distances in the specified range.";
                }
string EMAN::DistanceSegmentProcessor::get_name ( ) const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 750 of file processor.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::DistanceSegmentProcessor::get_param_types ( ) const [inline, virtual]

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 758 of file processor.h.

References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().

                {
                        TypeDict d ;
                        d.put("thr",EMObject::FLOAT,"Optional : Isosurface threshold value. Pixels below this will not be segment centers (default = 0.9)");
                        d.put("minsegsep",EMObject::FLOAT,"Required: Minimum segment separation in pixels. Segments too close will trigger a reseed");
                        d.put("maxsegsep",EMObject::FLOAT,"Required: Maximum segment separation in pixels. Segments too close will trigger a reseed");
                        d.put("verbose",EMObject::INT,"Be verbose while running");
                        return d;
                }
static Processor* EMAN::DistanceSegmentProcessor::NEW ( ) [inline, static]

Definition at line 768 of file processor.h.

                {
                        return new DistanceSegmentProcessor();
                }
EMData * DistanceSegmentProcessor::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 869 of file processor.cpp.

References EMAN::EMData::calc_highest_locations(), EMAN::EMData::copy(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Util::hypot3(), nx, ny, EMAN::Processor::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::set_value_at(), EMAN::Pixel::x, x, EMAN::Pixel::y, y, and EMAN::Pixel::z.

{
        EMData * result = image->copy();

        float thr = params.set_default("thr",0.9f);
        float minsegsep = params.set_default("minsegsep",5.0f);
        float maxsegsep = params.set_default("maxsegsep",5.1f);
        int verbose = params.set_default("verbose",0);

        vector<Pixel> pixels=image->calc_highest_locations(thr);

        vector<float> centers(3);       // only 1 to start
        int nx=image->get_xsize();
        int ny=image->get_ysize();
        int nz=image->get_zsize();
//      int nxy=nx*ny;

        // seed the process with the highest valued point
        centers[0]=(float)pixels[0].x;
        centers[1]=(float)pixels[0].y;
        centers[2]=(float)pixels[0].z;
        pixels.erase(pixels.begin());

        // outer loop. We add one center per iteration
        // This is NOT a very efficient algorithm, it assumes points are fairly sparse
        while (pixels.size()>0) {
                // iterate over pixels until we find a new center (then stop), delete any 'bad' pixels
                // no iterators because we remove elements

                for (unsigned int i=0; i<pixels.size(); i++) {

                        Pixel p=pixels[i];
                        // iterate over existing centers to see if this pixel should be removed ... technically we only should need to check the last center
                        for (unsigned int j=0; j<centers.size(); j+=3) {
                                float d=Util::hypot3(centers[j]-p.x,centers[j+1]-p.y,centers[j+2]-p.z);
                                if (d<minsegsep) {              // conflicts with existing center, erase
                                        pixels.erase(pixels.begin()+i);
                                        i--;
                                        break;
                                }
                        }
                }

                int found=0;
                for (unsigned int i=0; i<pixels.size() && found==0; i++) {
                        Pixel p=pixels[i];

                        // iterate again to see if this may be a new valid center. Start at the end so we tend to build chains
                        for (unsigned int j=centers.size()-3; j>0; j-=3) {
                                float d=Util::hypot3(centers[j]-p.x,centers[j+1]-p.y,centers[j+2]-p.z);
                                if (d<maxsegsep) {              // we passed minsegsep question already, so we know we're in the 'good' range
                                        centers.push_back((float)p.x);
                                        centers.push_back((float)p.y);
                                        centers.push_back((float)p.z);
                                        pixels.erase(pixels.begin()+i); // in the centers list now, don't need it any more
                                        found=1;
                                        break;
                                }
                        }
                }

                // If we went through the whole list and didn't find one, we need to reseed again
                if (!found && pixels.size()) {
                        if (verbose) printf("New chain\n");
                        centers.push_back((float)pixels[0].x);
                        centers.push_back((float)pixels[0].y);
                        centers.push_back((float)pixels[0].z);
                        pixels.erase(pixels.begin());
                }

                if (verbose) printf("%d points found\n",(int)(centers.size()/3));
        }

        // after we have our list of centers classify pixels
        for (int z=0; z<nz; z++) {
                for (int y=0; y<ny; y++) {
                        for (int x=0; x<nz; x++) {
                                if (image->get_value_at(x,y,z)<thr) {
                                        result->set_value_at(x,y,z,-1.0);               //below threshold -> -1 (unclassified)
                                        continue;
                                }
                                int bcls=-1;                    // best matching class
                                float bdist=(float)(nx+ny+nz);  // distance for best class
                                for (unsigned int c=0; c<centers.size()/3; c++) {
                                        float d=Util::hypot3(x-centers[c*3],y-centers[c*3+1],z-centers[c*3+2]);
                                        if (d<bdist) { bdist=d; bcls=c; }
                                }
                                result->set_value_at(x,y,z,(float)bcls);                // set the pixel to the class number
                        }
                }
        }

        result->set_attr("segment_centers",centers);

        return result;
}
void DistanceSegmentProcessor::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 862 of file processor.cpp.

{
        printf("Process inplace not implemented. Please use process.\n");
        return;
}

Member Data Documentation

const string DistanceSegmentProcessor::NAME = "segment.distance" [static]

Definition at line 778 of file processor.h.

Referenced by get_name().


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