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.

00020                                                                                                                                        {
00021 //                      math = new MathLib();
00022 //                      surfaceNormalFinder = new NormalFinder();
00023                         this->pointRadius = pointRadius;
00024                         this->curveRadius = curveRadius;
00025                         this->surfaceRadius = surfaceRadius;
00026                         this->skeletonDirectionRadius = skeletonDirectionRadius;
00027 
00028 //                      gaussianFilterPointRadius.radius = pointRadius;
00029 //                      math->GetBinomialDistribution(gaussianFilterPointRadius);
00030 //
00031 //                      gaussianFilterCurveRadius.radius = curveRadius;
00032 //                      math->GetBinomialDistribution(gaussianFilterCurveRadius);
00033 //
00034 //                      gaussianFilterSurfaceRadius.radius = surfaceRadius;
00035 //                      math->GetBinomialDistribution(gaussianFilterSurfaceRadius);
00036 //
00037 //                      gaussianFilterMaxRadius.radius = MAX_GAUSSIAN_FILTER_RADIUS;
00038 //                      math->GetBinomialDistribution(gaussianFilterMaxRadius);
00039 //
00040 //                      uniformFilterSkeletonDirectionRadius.radius = skeletonDirectionRadius;
00041 //                      math->GetUniformDistribution(uniformFilterSkeletonDirectionRadius);
00042                 }

VolumeSkeletonizer::~VolumeSkeletonizer (  ) 

Definition at line 44 of file skeletonizer.cpp.

00044                                                         {
00045                         //delete math;
00046                         //delete surfaceNormalFinder;
00047                 }


Member Function Documentation

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

Definition at line 54 of file skeletonizer.cpp.

References abs, and v.

Referenced by CleanUpSkeleton().

00054                                                                                 {
00055                         if ( u==v || abs(u[0]-v[0])>1 || abs(u[1]-v[1])>1 || abs(u[2]-v[2])>1) {
00056                                 return false;
00057                         } else { 
00058                                 return true;
00059                         }
00060                 }

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().

00094                                                                                                                   {
00095                         
00096                         //Get the indices of voxels that are above the threshold, i.e. part of the skeleton
00097                         list< Vec3<int> > skel_indices;
00098                         Vec3<int> voxel_indices;
00099                         for (int k=0; k < skeleton->getSizeZ(); k++) {
00100                                 for (int j=0; j < skeleton->getSizeY(); j++) {
00101                                         for (int i=0; i < skeleton->getSizeX(); i++) {
00102                                                 if (skeleton->getDataAt(i,j,k) > valueThreshold) {
00103                                                         voxel_indices.set_value(i,j,k);
00104                                                         skel_indices.push_front(voxel_indices);
00105                                                 }
00106                                         }
00107                                 }
00108                         }
00109                         
00110                         vector< Vec3<int> > segment; //the coordinates for a set of connected skeleton voxels
00111                         list< Vec3<int> >::iterator itr;
00112                         
00113                         /*
00114                          1. Group the connected voxels together
00115                          2. Check the number of voxels in that group
00116                          3. If below the minimum number of voxels, remove them from the skeleton
00117                          4. Repeat until all the voxels in the skeleton have been grouped (possibly alone if not connected)
00118                         */
00119                         while (skel_indices.size() > 0) {
00120                                 segment.clear();
00121                                 segment.push_back(skel_indices.front());
00122                                 skel_indices.pop_front();
00123                                 // group connected voxels -- each member of segment neighbors at least one other member of segment
00124                                 //For each voxel in segment, we test if each voxel in skel_indices is a neighbor
00125                                 for (unsigned int seg_ix=0; seg_ix < segment.size(); seg_ix++) { 
00126                                         for (itr = skel_indices.begin(); itr != skel_indices.end(); itr++) {
00127                                                 
00128                                                 if (Are26Neighbors(segment[seg_ix], *itr)) {
00129                                                         segment.push_back(*itr);
00130                                                         skel_indices.erase(itr);
00131                                                 }
00132                                         }
00133                                 } //Now, a segment is complete
00134                                 
00135 
00136                                 //If the region of connected voxels is too small, remove them from the map
00137                                 if (segment.size() < static_cast<unsigned int>(minNumVoxels)) {
00138                                         for (unsigned int ix=0; ix<segment.size(); ix++) {
00139                                                 skeleton->setDataAt(segment[ix][0], segment[ix][1], segment[ix][2],0.0f);
00140                                         }
00141                                 }
00142 
00143                         }
00144                 }

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().

00200                                                                                                                                     {
00201                         char thinningClass = is3D ? THINNING_CLASS_CURVE_PRESERVATION : THINNING_CLASS_CURVE_PRESERVATION_2D;
00202                         return GetJuThinning(sourceVolume, preserve, threshold, thinningClass);
00203                 }

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().

00205                                                                                                                            {
00206                         return GetJuThinning(sourceVolume, preserve, threshold, THINNING_CLASS_SURFACE_PRESERVATION);
00207                 }

Volume * VolumeSkeletonizer::GetJuThinning ( Volume sourceVolume,
Volume preserve,
double  threshold,
char  thinningClass 
) [static, private]

Definition at line 213 of file skeletonizer.cpp.

References wustl_mm::SkeletonMaker::Volume::curveSkeleton(), wustl_mm::SkeletonMaker::Volume::curveSkeleton2D(), wustl_mm::SkeletonMaker::Volume::getSizeX(), wustl_mm::SkeletonMaker::Volume::getSizeY(), wustl_mm::SkeletonMaker::Volume::getSizeZ(), wustl_mm::SkeletonMaker::Volume::skeleton(), wustl_mm::SkeletonMaker::Volume::surfaceSkeletonPres(), THINNING_CLASS_CURVE_PRESERVATION, THINNING_CLASS_CURVE_PRESERVATION_2D, THINNING_CLASS_SURFACE_PRESERVATION, and THINNING_CLASS_TOPOLOGY_PRESERVATION.

Referenced by GetJuCurveSkeleton(), GetJuSurfaceSkeleton(), and GetJuTopologySkeleton().

00213                                                                                                                                          {
00214                         Volume * thinnedVolume = new Volume(sourceVolume->getSizeX(), sourceVolume->getSizeY(), sourceVolume->getSizeZ(), 0, 0, 0, sourceVolume);
00215                         switch(thinningClass) {
00216                                 case THINNING_CLASS_SURFACE_PRESERVATION :
00217                                         thinnedVolume->surfaceSkeletonPres((float)threshold, preserve);
00218                                         break;
00219                                 case THINNING_CLASS_CURVE_PRESERVATION :
00220                                         thinnedVolume->curveSkeleton((float)threshold, preserve);
00221                                         break;
00222                                 case THINNING_CLASS_CURVE_PRESERVATION_2D :
00223                                         thinnedVolume->curveSkeleton2D((float)threshold, preserve);
00224                                         break;
00225                                 case THINNING_CLASS_TOPOLOGY_PRESERVATION :
00226                                         thinnedVolume->skeleton((float)threshold, preserve, preserve);
00227                         }
00228                         return thinnedVolume;
00229                 }

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().

00209                                                                                                                             {
00210                         return GetJuThinning(sourceVolume, preserve, threshold, THINNING_CLASS_TOPOLOGY_PRESERVATION);
00211                 }

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.

00063                                                                       {
00064 
00065                         int faceNeighbors[3][3][3] = {  {{1,0,0}, {1,0,1}, {0,0,1}},
00066                                                                                         {{1,0,0}, {1,1,0}, {0,1,0}},
00067                                                                                         {{0,1,0}, {0,1,1}, {0,0,1}} };
00068                         int indices[4];
00069                         bool faceFound;
00070 
00071                         for (int z = 0; z < skeleton->getSizeZ(); z++) {
00072                                 for (int y = 0; y < skeleton->getSizeY(); y++) {
00073                                         for (int x = 0; x < skeleton->getSizeX(); x++) {
00074 
00075                                                 indices[0] = skeleton->getIndex(x,y,z);
00076                                                 for (int n = 0; n < 3; n++) {
00077                                                         faceFound = true;
00078                                                         for (int m = 0; m < 3; m++) {
00079                                                                 indices[m+1] = skeleton->getIndex(x+faceNeighbors[n][m][0], y+faceNeighbors[n][m][1], z+faceNeighbors[n][m][2]);
00080                                                                 faceFound = faceFound && (skeleton->getDataAt(indices[m+1]) > 0);
00081                                                         }
00082                                                         if (faceFound) {
00083                                                                 for (int m = 0; m < 4; m++) {
00084                                                                         skeleton->setDataAt(indices[m], SURFACE_VAL);
00085                                                                 }
00086                                                         }
00087                                                 }
00088 
00089                                         }
00090                                 }
00091                         }
00092                 }

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().

00148                                                                                                                                                              {
00149                         imageVol->pad(MAX_GAUSSIAN_FILTER_RADIUS, 0);
00150                         Volume * preservedVol = new Volume(imageVol->getSizeX(), imageVol->getSizeY(), imageVol->getSizeZ());
00151                         Volume * surfaceVol;
00152                         Volume * curveVol;
00153                         Volume * topologyVol;
00154                         //printf("\t\t\tUSING THRESHOLD : %f\n", threshold);
00155                         // Skeletonizing while preserving surface features curve features and topology
00156                         surfaceVol = GetJuSurfaceSkeleton(imageVol, preservedVol, threshold);
00157                         PruneSurfaces(surfaceVol, minSurfaceWidth);
00158                         VoxelOr(preservedVol, surfaceVol);
00159                         curveVol = VolumeSkeletonizer::GetJuCurveSkeleton(imageVol, preservedVol, threshold, true);
00160                         VolumeSkeletonizer::PruneCurves(curveVol, minCurveWidth);
00161                         VoxelOr(preservedVol, curveVol);
00162 
00163                         topologyVol = VolumeSkeletonizer::GetJuTopologySkeleton(imageVol, preservedVol, threshold);
00164 
00165                         //Code below by Ross as a test -- to replace GetJuTopologySkeleton return value
00166 //                      int curveVolMax = curveVol->getVolumeData()->GetMaxIndex();
00167 //                      int surfaceVolMax = curveVol->getVolumeData()->GetMaxIndex();
00168 //                      int maximum = curveVolMax <= surfaceVolMax? curveVolMax : surfaceVolMax;
00169 //                      if (curveVolMax != surfaceVolMax)
00170 //                              cout << "Curve Skeleton: " << curveVolMax << '\n' << "Surface Skeleton" << surfaceVolMax << endl;
00171 //                      topologyVol = new Volume(curveVol->getSizeX(), curveVol->getSizeY(), curveVol->getSizeZ());
00172 //                      float val, cval, sval;
00173 //                      for (int i = 0; i < maximum; i++)
00174 //                      {
00175 //                              cval = float(curveVol->getDataAt(i));
00176 //                              sval = float(surfaceVol->getDataAt(i));
00177 //                              if (cval && sval)
00178 //                                      val = 100; //Something went wrong!
00179 //                              else if (cval)
00180 //                                      val = 1;
00181 //                              else if (sval)
00182 //                                      val = -1;
00183 //                              else
00184 //                                      val = 0;
00185 //                              topologyVol->setDataAt(i, val);
00186 //                      }
00187 
00188 
00189 
00190 
00191 
00192                         imageVol->pad(-MAX_GAUSSIAN_FILTER_RADIUS, 0);
00193                         topologyVol->pad(-MAX_GAUSSIAN_FILTER_RADIUS, 0);
00194                         delete preservedVol;
00195                         delete surfaceVol;
00196                         delete curveVol;
00197                         return topologyVol;
00198                 }

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().

00231                                                                                            {
00232                         sourceVolume->erodeHelix(pruneLength);
00233                 }

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().

00234                                                                                              {
00235                         sourceVolume->erodeSheet(pruneLength);
00236                 }

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().

00238                                                                                                      {
00239                         if(sourceVolume2 != NULL) {
00240                                 for(int x = 0; x < sourceAndDestVolume1->getSizeX(); x++) {
00241                                         for(int y = 0; y < sourceAndDestVolume1->getSizeY(); y++) {
00242                                                 for(int z = 0; z < sourceAndDestVolume1->getSizeZ(); z++) {
00243                                                         sourceAndDestVolume1->setDataAt(x, y, z, max(sourceAndDestVolume1->getDataAt(x, y, z), sourceVolume2->getDataAt(x, y, z)));
00244                                                 }
00245                                         }
00246                                 }
00247                         }
00248                 }


Member Data Documentation

int wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::curveRadius [private]

Definition at line 54 of file skeletonizer.h.

int wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::pointRadius [private]

Definition at line 53 of file skeletonizer.h.

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.

int wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::skeletonDirectionRadius [private]

Definition at line 56 of file skeletonizer.h.

int wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::surfaceRadius [private]

Definition at line 55 of file skeletonizer.h.

const char VolumeSkeletonizer::THINNING_CLASS_CURVE_PRESERVATION = 2 [static, private]

Definition at line 39 of file skeletonizer.h.

Referenced by GetJuCurveSkeleton(), and GetJuThinning().

const char VolumeSkeletonizer::THINNING_CLASS_CURVE_PRESERVATION_2D = 3 [static, private]

Definition at line 38 of file skeletonizer.h.

Referenced by GetJuCurveSkeleton(), and GetJuThinning().

const char VolumeSkeletonizer::THINNING_CLASS_POINT_PRESERVATION = 1 [static, private]

Definition at line 40 of file skeletonizer.h.

const char VolumeSkeletonizer::THINNING_CLASS_SURFACE_PRESERVATION = 4 [static, private]

Definition at line 37 of file skeletonizer.h.

Referenced by GetJuSurfaceSkeleton(), and GetJuThinning().

const char VolumeSkeletonizer::THINNING_CLASS_TOPOLOGY_PRESERVATION = 0 [static, private]

Definition at line 41 of file skeletonizer.h.

Referenced by GetJuThinning(), and GetJuTopologySkeleton().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:45:39 2013 for EMAN2 by  doxygen 1.4.7