#include <processor.h>
Inheritance diagram for EMAN::DistanceSegmentProcessor:
Public Member Functions | |
string | get_name () const |
Get the processor's name. | |
virtual EMData * | process (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 Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "segment.distance" |
For linear densities such as skeletons this should fill linear regions with uniformly separated points
Definition at line 704 of file processor.h.
string EMAN::DistanceSegmentProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 730 of file processor.h.
00731 { 00732 return "Segments a volume into pieces separated by distances in the specified range."; 00733 }
string EMAN::DistanceSegmentProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 707 of file processor.h.
References NAME.
00708 { 00709 return NAME; 00710 }
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.
Reimplemented from EMAN::Processor.
Definition at line 715 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00716 { 00717 TypeDict d ; 00718 d.put("thr",EMObject::FLOAT,"Optional : Isosurface threshold value. Pixels below this will not be segment centers (default = 0.9)"); 00719 d.put("minsegsep",EMObject::FLOAT,"Required: Minimum segment separation in pixels. Segments too close will trigger a reseed"); 00720 d.put("maxsegsep",EMObject::FLOAT,"Required: Maximum segment separation in pixels. Segments too close will trigger a reseed"); 00721 d.put("verbose",EMObject::INT,"Be verbose while running"); 00722 return d; 00723 }
static Processor* EMAN::DistanceSegmentProcessor::NEW | ( | ) | [inline, static] |
Definition at line 725 of file processor.h.
00726 { 00727 return new DistanceSegmentProcessor(); 00728 }
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.
image | The image will be copied, actual process happen on copy of image. |
Reimplemented from EMAN::Processor.
Definition at line 788 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(), x, and y.
00789 { 00790 EMData * result = image->copy(); 00791 00792 float thr = params.set_default("thr",0.9f); 00793 float minsegsep = params.set_default("minsegsep",5.0f); 00794 float maxsegsep = params.set_default("maxsegsep",5.1f); 00795 int verbose = params.set_default("verbose",0); 00796 00797 vector<Pixel> pixels=image->calc_highest_locations(thr); 00798 00799 vector<float> centers(3); // only 1 to start 00800 int nx=image->get_xsize(); 00801 int ny=image->get_ysize(); 00802 int nz=image->get_zsize(); 00803 // int nxy=nx*ny; 00804 00805 // seed the process with the highest valued point 00806 centers[0]=(float)pixels[0].x; 00807 centers[1]=(float)pixels[0].y; 00808 centers[2]=(float)pixels[0].z; 00809 pixels.erase(pixels.begin()); 00810 00811 // outer loop. We add one center per iteration 00812 // This is NOT a very efficient algorithm, it assumes points are fairly sparse 00813 while (pixels.size()>0) { 00814 // iterate over pixels until we find a new center (then stop), delete any 'bad' pixels 00815 // no iterators because we remove elements 00816 00817 for (unsigned int i=0; i<pixels.size(); i++) { 00818 00819 Pixel p=pixels[i]; 00820 // iterate over existing centers to see if this pixel should be removed ... technically we only should need to check the last center 00821 for (unsigned int j=0; j<centers.size(); j+=3) { 00822 float d=Util::hypot3(centers[j]-p.x,centers[j+1]-p.y,centers[j+2]-p.z); 00823 if (d<minsegsep) { // conflicts with existing center, erase 00824 pixels.erase(pixels.begin()+i); 00825 i--; 00826 break; 00827 } 00828 } 00829 } 00830 00831 int found=0; 00832 for (unsigned int i=0; i<pixels.size() && found==0; i++) { 00833 Pixel p=pixels[i]; 00834 00835 // iterate again to see if this may be a new valid center. Start at the end so we tend to build chains 00836 for (unsigned int j=centers.size()-3; j>0; j-=3) { 00837 float d=Util::hypot3(centers[j]-p.x,centers[j+1]-p.y,centers[j+2]-p.z); 00838 if (d<maxsegsep) { // we passed minsegsep question already, so we know we're in the 'good' range 00839 centers.push_back((float)p.x); 00840 centers.push_back((float)p.y); 00841 centers.push_back((float)p.z); 00842 pixels.erase(pixels.begin()+i); // in the centers list now, don't need it any more 00843 found=1; 00844 break; 00845 } 00846 } 00847 } 00848 00849 // If we went through the whole list and didn't find one, we need to reseed again 00850 if (!found && pixels.size()) { 00851 if (verbose) printf("New chain\n"); 00852 centers.push_back((float)pixels[0].x); 00853 centers.push_back((float)pixels[0].y); 00854 centers.push_back((float)pixels[0].z); 00855 pixels.erase(pixels.begin()); 00856 } 00857 00858 if (verbose) printf("%d points found\n",(int)(centers.size()/3)); 00859 } 00860 00861 // after we have our list of centers classify pixels 00862 for (int z=0; z<nz; z++) { 00863 for (int y=0; y<ny; y++) { 00864 for (int x=0; x<nz; x++) { 00865 if (image->get_value_at(x,y,z)<thr) { 00866 result->set_value_at(x,y,z,-1.0); //below threshold -> -1 (unclassified) 00867 continue; 00868 } 00869 int bcls=-1; // best matching class 00870 float bdist=(float)(nx+ny+nz); // distance for best class 00871 for (unsigned int c=0; c<centers.size()/3; c++) { 00872 float d=Util::hypot3(x-centers[c*3],y-centers[c*3+1],z-centers[c*3+2]); 00873 if (d<bdist) { bdist=d; bcls=c; } 00874 } 00875 result->set_value_at(x,y,z,(float)bcls); // set the pixel to the class number 00876 } 00877 } 00878 } 00879 00880 result->set_attr("segment_centers",centers); 00881 00882 return result; 00883 }
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 781 of file processor.cpp.
00782 { 00783 printf("Process inplace not implemented. Please use process.\n"); 00784 return; 00785 }
const string DistanceSegmentProcessor::NAME = "segment.distance" [static] |