EMAN2
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
wustl_mm::GraySkeletonCPP::VolumeSkeletonizer Class Reference

#include <skeletonizer.h>

List of all members.

Public Member Functions

 VolumeSkeletonizer (int pointRadius, int curveRadius, int surfaceRadius, int skeletonDirectionRadius=DEFAULT_SKELETON_DIRECTION_RADIUS)
 ~VolumeSkeletonizer ()

Static Public Member Functions

static VolumePerformPureJuSkeletonization (Volume *imageVol, string outputPath, double threshold, int minCurveWidth, int minSurfaceWidth)
static void CleanUpSkeleton (Volume *skeleton, int minNumVoxels=4, float valueThreshold=0.5)
static void MarkSurfaces (Volume *skeleton)

Static Private Member Functions

static bool Are26Neighbors (Vec3< int > u, Vec3< int > v)
static VolumeGetJuSurfaceSkeleton (Volume *sourceVolume, Volume *preserve, double threshold)
static VolumeGetJuCurveSkeleton (Volume *sourceVolume, Volume *preserve, double threshold, bool is3D)
static VolumeGetJuTopologySkeleton (Volume *sourceVolume, Volume *preserve, double threshold)
static void PruneCurves (Volume *sourceVolume, int pruneLength)
static void PruneSurfaces (Volume *sourceVolume, int pruneLength)
static void VoxelOr (Volume *sourceAndDestVolume1, Volume *sourceVolume2)
static VolumeGetJuThinning (Volume *sourceVolume, Volume *preserve, double threshold, char thinningClass)

Private Attributes

int pointRadius
int curveRadius
int surfaceRadius
int skeletonDirectionRadius

Static Private Attributes

static const char THINNING_CLASS_SURFACE_PRESERVATION = 4
static const char THINNING_CLASS_CURVE_PRESERVATION_2D = 3
static const char THINNING_CLASS_CURVE_PRESERVATION = 2
static const char THINNING_CLASS_POINT_PRESERVATION = 1
static const char THINNING_CLASS_TOPOLOGY_PRESERVATION = 0
static const char PRUNING_CLASS_PRUNE_SURFACES = 5
static const char PRUNING_CLASS_PRUNE_CURVES = 6
static const char PRUNING_CLASS_PRUNE_POINTS = 7

Detailed Description

Definition at line 17 of file skeletonizer.h.


Constructor & Destructor Documentation

VolumeSkeletonizer::VolumeSkeletonizer ( int  pointRadius,
int  curveRadius,
int  surfaceRadius,
int  skeletonDirectionRadius = DEFAULT_SKELETON_DIRECTION_RADIUS 
)

Definition at line 20 of file skeletonizer.cpp.

References curveRadius, pointRadius, skeletonDirectionRadius, and surfaceRadius.

                                                                                                                                       {
//                      math = new MathLib();
//                      surfaceNormalFinder = new NormalFinder();
                        this->pointRadius = pointRadius;
                        this->curveRadius = curveRadius;
                        this->surfaceRadius = surfaceRadius;
                        this->skeletonDirectionRadius = skeletonDirectionRadius;

//                      gaussianFilterPointRadius.radius = pointRadius;
//                      math->GetBinomialDistribution(gaussianFilterPointRadius);
//
//                      gaussianFilterCurveRadius.radius = curveRadius;
//                      math->GetBinomialDistribution(gaussianFilterCurveRadius);
//
//                      gaussianFilterSurfaceRadius.radius = surfaceRadius;
//                      math->GetBinomialDistribution(gaussianFilterSurfaceRadius);
//
//                      gaussianFilterMaxRadius.radius = MAX_GAUSSIAN_FILTER_RADIUS;
//                      math->GetBinomialDistribution(gaussianFilterMaxRadius);
//
//                      uniformFilterSkeletonDirectionRadius.radius = skeletonDirectionRadius;
//                      math->GetUniformDistribution(uniformFilterSkeletonDirectionRadius);
                }
VolumeSkeletonizer::~VolumeSkeletonizer ( )

Definition at line 44 of file skeletonizer.cpp.

                                                        {
                        //delete math;
                        //delete surfaceNormalFinder;
                }

Member Function Documentation

bool VolumeSkeletonizer::Are26Neighbors ( Vec3< int >  u,
Vec3< int >  v 
) [static, private]

Definition at line 54 of file skeletonizer.cpp.

References abs.

Referenced by CleanUpSkeleton().

                                                                                {
                        if ( u==v || abs(u[0]-v[0])>1 || abs(u[1]-v[1])>1 || abs(u[2]-v[2])>1) {
                                return false;
                        } else { 
                                return true;
                        }
                }
void VolumeSkeletonizer::CleanUpSkeleton ( Volume skeleton,
int  minNumVoxels = 4,
float  valueThreshold = 0.5 
) [static]

Definition at line 94 of file skeletonizer.cpp.

References Are26Neighbors(), wustl_mm::SkeletonMaker::Volume::getDataAt(), wustl_mm::SkeletonMaker::Volume::getSizeX(), wustl_mm::SkeletonMaker::Volume::getSizeY(), wustl_mm::SkeletonMaker::Volume::getSizeZ(), EMAN::Vec3< Type >::set_value(), and wustl_mm::SkeletonMaker::Volume::setDataAt().

                                                                                                                  {
                        
                        //Get the indices of voxels that are above the threshold, i.e. part of the skeleton
                        list< Vec3<int> > skel_indices;
                        Vec3<int> voxel_indices;
                        for (int k=0; k < skeleton->getSizeZ(); k++) {
                                for (int j=0; j < skeleton->getSizeY(); j++) {
                                        for (int i=0; i < skeleton->getSizeX(); i++) {
                                                if (skeleton->getDataAt(i,j,k) > valueThreshold) {
                                                        voxel_indices.set_value(i,j,k);
                                                        skel_indices.push_front(voxel_indices);
                                                }
                                        }
                                }
                        }
                        
                        vector< Vec3<int> > segment; //the coordinates for a set of connected skeleton voxels
                        list< Vec3<int> >::iterator itr;
                        
                        /*
                         1. Group the connected voxels together
                         2. Check the number of voxels in that group
                         3. If below the minimum number of voxels, remove them from the skeleton
                         4. Repeat until all the voxels in the skeleton have been grouped (possibly alone if not connected)
                        */
                        while (skel_indices.size() > 0) {
                                segment.clear();
                                segment.push_back(skel_indices.front());
                                skel_indices.pop_front();
                                // group connected voxels -- each member of segment neighbors at least one other member of segment
                                //For each voxel in segment, we test if each voxel in skel_indices is a neighbor
                                for (unsigned int seg_ix=0; seg_ix < segment.size(); seg_ix++) { 
                                        for (itr = skel_indices.begin(); itr != skel_indices.end(); itr++) {
                                                
                                                if (Are26Neighbors(segment[seg_ix], *itr)) {
                                                        segment.push_back(*itr);
                                                        skel_indices.erase(itr);
                                                }
                                        }
                                } //Now, a segment is complete
                                

                                //If the region of connected voxels is too small, remove them from the map
                                if (segment.size() < static_cast<unsigned int>(minNumVoxels)) {
                                        for (unsigned int ix=0; ix<segment.size(); ix++) {
                                                skeleton->setDataAt(segment[ix][0], segment[ix][1], segment[ix][2],0.0f);
                                        }
                                }

                        }
                }
Volume * VolumeSkeletonizer::GetJuCurveSkeleton ( Volume sourceVolume,
Volume preserve,
double  threshold,
bool  is3D 
) [static, private]

Definition at line 200 of file skeletonizer.cpp.

References GetJuThinning(), THINNING_CLASS_CURVE_PRESERVATION, and THINNING_CLASS_CURVE_PRESERVATION_2D.

Referenced by PerformPureJuSkeletonization().

                                                                                                                                    {
                        char thinningClass = is3D ? THINNING_CLASS_CURVE_PRESERVATION : THINNING_CLASS_CURVE_PRESERVATION_2D;
                        return GetJuThinning(sourceVolume, preserve, threshold, thinningClass);
                }
Volume * VolumeSkeletonizer::GetJuSurfaceSkeleton ( Volume sourceVolume,
Volume preserve,
double  threshold 
) [static, private]

Definition at line 205 of file skeletonizer.cpp.

References GetJuThinning(), and THINNING_CLASS_SURFACE_PRESERVATION.

Referenced by PerformPureJuSkeletonization().

                                                                                                                           {
                        return GetJuThinning(sourceVolume, preserve, threshold, THINNING_CLASS_SURFACE_PRESERVATION);
                }
Volume * VolumeSkeletonizer::GetJuThinning ( Volume sourceVolume,
Volume preserve,
double  threshold,
char  thinningClass 
) [static, private]
Volume * VolumeSkeletonizer::GetJuTopologySkeleton ( Volume sourceVolume,
Volume preserve,
double  threshold 
) [static, private]

Definition at line 209 of file skeletonizer.cpp.

References GetJuThinning(), and THINNING_CLASS_TOPOLOGY_PRESERVATION.

Referenced by PerformPureJuSkeletonization().

                                                                                                                            {
                        return GetJuThinning(sourceVolume, preserve, threshold, THINNING_CLASS_TOPOLOGY_PRESERVATION);
                }
void VolumeSkeletonizer::MarkSurfaces ( Volume skeleton) [static]

Definition at line 63 of file skeletonizer.cpp.

References wustl_mm::SkeletonMaker::Volume::getDataAt(), wustl_mm::SkeletonMaker::Volume::getIndex(), wustl_mm::SkeletonMaker::Volume::getSizeX(), wustl_mm::SkeletonMaker::Volume::getSizeY(), wustl_mm::SkeletonMaker::Volume::getSizeZ(), wustl_mm::SkeletonMaker::Volume::setDataAt(), SURFACE_VAL, x, and y.

                                                                      {

                        int faceNeighbors[3][3][3] = {  {{1,0,0}, {1,0,1}, {0,0,1}},
                                                                                        {{1,0,0}, {1,1,0}, {0,1,0}},
                                                                                        {{0,1,0}, {0,1,1}, {0,0,1}} };
                        int indices[4];
                        bool faceFound;

                        for (int z = 0; z < skeleton->getSizeZ(); z++) {
                                for (int y = 0; y < skeleton->getSizeY(); y++) {
                                        for (int x = 0; x < skeleton->getSizeX(); x++) {

                                                indices[0] = skeleton->getIndex(x,y,z);
                                                for (int n = 0; n < 3; n++) {
                                                        faceFound = true;
                                                        for (int m = 0; m < 3; m++) {
                                                                indices[m+1] = skeleton->getIndex(x+faceNeighbors[n][m][0], y+faceNeighbors[n][m][1], z+faceNeighbors[n][m][2]);
                                                                faceFound = faceFound && (skeleton->getDataAt(indices[m+1]) > 0);
                                                        }
                                                        if (faceFound) {
                                                                for (int m = 0; m < 4; m++) {
                                                                        skeleton->setDataAt(indices[m], SURFACE_VAL);
                                                                }
                                                        }
                                                }

                                        }
                                }
                        }
                }
Volume * VolumeSkeletonizer::PerformPureJuSkeletonization ( Volume imageVol,
string  outputPath,
double  threshold,
int  minCurveWidth,
int  minSurfaceWidth 
) [static]

Definition at line 148 of file skeletonizer.cpp.

References GetJuCurveSkeleton(), GetJuSurfaceSkeleton(), GetJuTopologySkeleton(), wustl_mm::SkeletonMaker::Volume::getSizeX(), wustl_mm::SkeletonMaker::Volume::getSizeY(), wustl_mm::SkeletonMaker::Volume::getSizeZ(), MAX_GAUSSIAN_FILTER_RADIUS, wustl_mm::SkeletonMaker::Volume::pad(), PruneCurves(), PruneSurfaces(), and VoxelOr().

                                                                                                                                                             {
                        imageVol->pad(MAX_GAUSSIAN_FILTER_RADIUS, 0);
                        Volume * preservedVol = new Volume(imageVol->getSizeX(), imageVol->getSizeY(), imageVol->getSizeZ());
                        Volume * surfaceVol;
                        Volume * curveVol;
                        Volume * topologyVol;
                        //printf("\t\t\tUSING THRESHOLD : %f\n", threshold);
                        // Skeletonizing while preserving surface features curve features and topology
                        surfaceVol = GetJuSurfaceSkeleton(imageVol, preservedVol, threshold);
                        PruneSurfaces(surfaceVol, minSurfaceWidth);
                        VoxelOr(preservedVol, surfaceVol);
                        curveVol = VolumeSkeletonizer::GetJuCurveSkeleton(imageVol, preservedVol, threshold, true);
                        VolumeSkeletonizer::PruneCurves(curveVol, minCurveWidth);
                        VoxelOr(preservedVol, curveVol);

                        topologyVol = VolumeSkeletonizer::GetJuTopologySkeleton(imageVol, preservedVol, threshold);

                        //Code below by Ross as a test -- to replace GetJuTopologySkeleton return value
//                      int curveVolMax = curveVol->getVolumeData()->GetMaxIndex();
//                      int surfaceVolMax = curveVol->getVolumeData()->GetMaxIndex();
//                      int maximum = curveVolMax <= surfaceVolMax? curveVolMax : surfaceVolMax;
//                      if (curveVolMax != surfaceVolMax)
//                              cout << "Curve Skeleton: " << curveVolMax << '\n' << "Surface Skeleton" << surfaceVolMax << endl;
//                      topologyVol = new Volume(curveVol->getSizeX(), curveVol->getSizeY(), curveVol->getSizeZ());
//                      float val, cval, sval;
//                      for (int i = 0; i < maximum; i++)
//                      {
//                              cval = float(curveVol->getDataAt(i));
//                              sval = float(surfaceVol->getDataAt(i));
//                              if (cval && sval)
//                                      val = 100; //Something went wrong!
//                              else if (cval)
//                                      val = 1;
//                              else if (sval)
//                                      val = -1;
//                              else
//                                      val = 0;
//                              topologyVol->setDataAt(i, val);
//                      }





                        imageVol->pad(-MAX_GAUSSIAN_FILTER_RADIUS, 0);
                        topologyVol->pad(-MAX_GAUSSIAN_FILTER_RADIUS, 0);
                        delete preservedVol;
                        delete surfaceVol;
                        delete curveVol;
                        return topologyVol;
                }
void VolumeSkeletonizer::PruneCurves ( Volume sourceVolume,
int  pruneLength 
) [static, private]

Definition at line 231 of file skeletonizer.cpp.

References wustl_mm::SkeletonMaker::Volume::erodeHelix().

Referenced by PerformPureJuSkeletonization().

                                                                                           {
                        sourceVolume->erodeHelix(pruneLength);
                }
void VolumeSkeletonizer::PruneSurfaces ( Volume sourceVolume,
int  pruneLength 
) [static, private]

Definition at line 234 of file skeletonizer.cpp.

References wustl_mm::SkeletonMaker::Volume::erodeSheet().

Referenced by PerformPureJuSkeletonization().

                                                                                             {
                        sourceVolume->erodeSheet(pruneLength);
                }
void VolumeSkeletonizer::VoxelOr ( Volume sourceAndDestVolume1,
Volume sourceVolume2 
) [static, private]

Definition at line 238 of file skeletonizer.cpp.

References wustl_mm::SkeletonMaker::Volume::getDataAt(), wustl_mm::SkeletonMaker::Volume::getSizeX(), wustl_mm::SkeletonMaker::Volume::getSizeY(), wustl_mm::SkeletonMaker::Volume::getSizeZ(), max, wustl_mm::SkeletonMaker::Volume::setDataAt(), x, and y.

Referenced by PerformPureJuSkeletonization().

                                                                                                     {
                        if(sourceVolume2 != NULL) {
                                for(int x = 0; x < sourceAndDestVolume1->getSizeX(); x++) {
                                        for(int y = 0; y < sourceAndDestVolume1->getSizeY(); y++) {
                                                for(int z = 0; z < sourceAndDestVolume1->getSizeZ(); z++) {
                                                        sourceAndDestVolume1->setDataAt(x, y, z, max(sourceAndDestVolume1->getDataAt(x, y, z), sourceVolume2->getDataAt(x, y, z)));
                                                }
                                        }
                                }
                        }
                }

Member Data Documentation

Definition at line 54 of file skeletonizer.h.

Referenced by VolumeSkeletonizer().

Definition at line 53 of file skeletonizer.h.

Referenced by VolumeSkeletonizer().

const char VolumeSkeletonizer::PRUNING_CLASS_PRUNE_CURVES = 6 [static, private]

Definition at line 43 of file skeletonizer.h.

const char VolumeSkeletonizer::PRUNING_CLASS_PRUNE_POINTS = 7 [static, private]

Definition at line 44 of file skeletonizer.h.

const char VolumeSkeletonizer::PRUNING_CLASS_PRUNE_SURFACES = 5 [static, private]

Definition at line 42 of file skeletonizer.h.

Definition at line 56 of file skeletonizer.h.

Referenced by VolumeSkeletonizer().

Definition at line 55 of file skeletonizer.h.

Referenced by VolumeSkeletonizer().

Definition at line 39 of file skeletonizer.h.

Referenced by GetJuCurveSkeleton(), and GetJuThinning().

Definition at line 38 of file skeletonizer.h.

Referenced by GetJuCurveSkeleton(), and GetJuThinning().

Definition at line 40 of file skeletonizer.h.

Definition at line 37 of file skeletonizer.h.

Referenced by GetJuSurfaceSkeleton(), and GetJuThinning().

Definition at line 41 of file skeletonizer.h.

Referenced by GetJuThinning(), and GetJuTopologySkeleton().


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