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