KWStyle - itkBinaryBallStructuringElement.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkBinaryBallStructuringElement.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkBinaryBallStructuringElement_txx
18 DEF #define _itkBinaryBallStructuringElement_txx
19 #include "itkBinaryBallStructuringElement.h"
20
21 #include "itkImage.h"
22 #include "itkImageRegionIterator.h"
23 #include "itkFloodFilledSpatialFunctionConditionalIterator.h"
24 #include "itkEllipsoidInteriorExteriorSpatialFunction.h" 
25
26 namespace itk
27 {
28
29 // Create the structuring element
30 template <class TPixel, unsigned int VDimension, class TAllocator>
31 void
32 BinaryBallStructuringElement<TPixel, VDimension, TAllocator>
33 ::CreateStructuringElement()
34 {
35   unsigned int i;
36   
37   // Image typedef
38   typedef Image<TPixel, VDimension> ImageType;
39
40   // Create an image to hold the ellipsoid
41   //
42   typename ImageType::Pointer sourceImage = ImageType::New();
43   typename ImageType::RegionType region;
44   region.SetSize( this->GetSize() );
45
46   sourceImage->SetLargestPossibleRegion( region );
47   sourceImage->SetBufferedRegion( region );
48   sourceImage->SetRequestedRegion( region );
49   sourceImage->Allocate();
50
51   // Set the background to be zero
52   //
53   ImageRegionIterator<ImageType> it =
54 IND ****ImageRegionIterator<ImageType>(sourceImage, region);
55
56   for(it.GoToBegin(); !it.IsAtEnd(); ++it)
57     {
58     it.Set(NumericTraits<TPixel>::Zero);
59     }
60
61   
62   // Create the ellipsoid
63   //
64
65   // Ellipsoid spatial function typedef
66   typedef EllipsoidInteriorExteriorSpatialFunction<VDimension>
67 IND ****EllipsoidType;
68   
69   // Create an ellipsoid spatial function for the source image
70   typename EllipsoidType::Pointer spatialFunction = EllipsoidType::New();
71
72   // Define and set the axes lengths for the ellipsoid
73   typename EllipsoidType::InputType axes;
74   for (i=0; i < VDimension; i++)
75     {
76     axes[i] = this->GetSize(i);
77     }
78   spatialFunction->SetAxes( axes );
79
80   // Define and set the center of the ellipsoid in physical space
81   typename EllipsoidType::InputType center;
82   for (i=0; i < VDimension; i++)
83     {
84     // put the center of ellipse in the middle of the center pixel
85     center[i] = this->GetRadius(i) + 0.5; 
86     }
87   spatialFunction->SetCenter( center );
88
89   // Define the orientations of the ellipsoid axes, for now, we'll use
90   // the identify matrix
91   typename EllipsoidType::OrientationType orientations;
92   orientations.fill( 0.0 );
93   orientations.fill_diagonal( 1.0 );
94   spatialFunction->SetOrientations(orientations);
95
96   typename ImageType::IndexType seed;
97   for (i=0; i < VDimension; i++)
98     {
99     seed[i] = this->GetRadius(i);
100     }
101   FloodFilledSpatialFunctionConditionalIterator<ImageType, EllipsoidType> 
102 IND ****sfi = FloodFilledSpatialFunctionConditionalIterator<ImageType,
103     EllipsoidType>(sourceImage, spatialFunction, seed);
104   sfi.SetCenterInclusionStrategy();
105   
106   // Iterate through the entire image and set interior pixels to 1
107   for(; !sfi.IsAtEnd(); ++sfi)
108     {
109     sfi.Set(NumericTraits<TPixel>::One);
110     }
111
112   
113   // Copy the ellipsoid into the kernel
114   //
115   Iterator kernel_it;
116   for (it.GoToBegin(), kernel_it=this->Begin(); !it.IsAtEnd();
117 IND *******++it, ++kernel_it)
118     {
119     *kernel_it = it.Get();
120     }
121
122   // Clean up
123   //   ...temporary image should be cleaned up by SmartPointers automatically
124   
125 }
126
127 // namespace itk
128
129 #endif
130

Generated by KWStyle 1.0b on Tuesday January,17 at 02:13:59PM
© Kitware Inc.