ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkVoronoiSegmentationImageFilterBase_h 00019 #define __itkVoronoiSegmentationImageFilterBase_h 00020 00021 #include "itkImageToImageFilter.h" 00022 #include "itkVoronoiDiagram2DGenerator.h" 00023 #include "itkImage.h" 00024 00025 namespace itk 00026 { 00058 template< class TInputImage, class TOutputImage, class TBinaryPriorImage = Image< unsigned char, 2 > > 00059 class ITK_EXPORT VoronoiSegmentationImageFilterBase: 00060 public ImageToImageFilter< TInputImage, TOutputImage > 00061 { 00062 public: 00064 typedef VoronoiSegmentationImageFilterBase Self; 00065 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass; 00066 typedef SmartPointer< Self > Pointer; 00067 typedef SmartPointer< const Self > ConstPointer; 00068 00070 itkNewMacro(Self); 00071 00073 itkTypeMacro(VoronoiSegmentationImageFilterBase, ImageToImageFilter); 00074 00076 itkStaticConstMacro(ImageDimension, unsigned int, 00077 TInputImage::ImageDimension); 00078 00080 typedef TInputImage InputImageType; 00081 typedef typename TInputImage::Pointer InputImagePointer; 00082 typedef typename TInputImage::ConstPointer InputImageConstPointer; 00083 typedef typename TInputImage::IndexType IndexType; 00084 typedef typename TInputImage::SizeType SizeType; 00085 typedef typename TInputImage::RegionType RegionType; 00086 typedef typename TInputImage::PixelType PixelType; 00087 00088 typedef TOutputImage OutputImageType; 00089 typedef typename TOutputImage::PixelType OutputPixelType; 00090 00091 typedef VoronoiDiagram2D< double > VoronoiDiagram; 00092 typedef VoronoiDiagram2DGenerator< double > VoronoiDiagramGenerator; 00093 typedef typename VoronoiDiagram::PointType PointType; 00094 typedef typename VoronoiDiagram::CellType CellType; 00095 typedef typename VoronoiDiagram::CellAutoPointer CellAutoPointer; 00096 typedef typename VoronoiDiagram::Pointer VoronoiPointer; 00097 typedef typename CellType::PointIdIterator PointIdIterator; 00098 typedef typename VoronoiDiagram::SeedsType SeedsType; 00099 typedef typename VoronoiDiagram::SeedsIterator SeedsIterator; 00100 typedef typename VoronoiDiagram::NeighborIdIterator NeighborIdIterator; 00101 typedef typename VoronoiDiagram::VoronoiEdgeIterator EdgeIterator; 00102 typedef typename VoronoiDiagram::VoronoiEdge EdgeInfo; 00103 typedef std::vector< PointType > PointTypeVector; 00104 typedef std::deque< PointType > PointTypeDeque; 00105 typedef TBinaryPriorImage BinaryObjectImage; 00106 typedef typename BinaryObjectImage::Pointer BinaryObjectImagePointer; 00107 typedef std::vector< IndexType > IndexList; 00108 00110 typedef Image< unsigned char, 2 > VDImage; 00111 typedef typename VDImage::Pointer VDImagePointer; 00112 00114 itkSetMacro(NumberOfSeeds, int); 00115 itkGetConstMacro(NumberOfSeeds, int); 00117 00119 itkSetMacro(MinRegion, int); 00120 itkGetConstMacro(MinRegion, int); 00122 00125 itkSetMacro(Steps, int); 00126 itkGetConstMacro(Steps, int); 00128 00130 itkGetConstMacro(LastStepSeeds, int); 00131 00133 itkGetConstMacro(NumberOfSeedsToAdded, int); 00134 00136 itkSetMacro(UseBackgroundInAPrior, bool); 00137 itkGetConstMacro(UseBackgroundInAPrior, bool); 00139 00141 itkSetMacro(OutputBoundary, bool); 00142 itkGetConstMacro(OutputBoundary, bool); 00144 00147 itkSetMacro(InteractiveSegmentation, bool); 00148 itkGetConstMacro(InteractiveSegmentation, bool); 00149 itkBooleanMacro(InteractiveSegmentation); 00151 00153 itkSetMacro(MeanDeviation, double); 00154 itkGetConstMacro(MeanDeviation, double); 00156 00158 itkSetMacro(Size, SizeType); 00159 itkGetConstMacro(Size, SizeType); 00161 00164 virtual void TakeAPrior(const BinaryObjectImage *){} 00165 00167 void RunSegment(void); 00168 00170 void RunSegmentOneStep(void); 00171 00173 virtual void MakeSegmentBoundary(void); 00174 00175 virtual void MakeSegmentObject(void); 00176 00178 VoronoiPointer GetVoronoiDiagram(void) 00179 { return m_WorkingVD; } 00180 00181 #if !defined( CABLE_CONFIGURATION ) // generates invalid iterator instantiation 00182 // with msvc 00186 void SetSeeds(int num, SeedsIterator begin) 00187 { 00188 m_NumberOfSeeds = num; 00189 m_WorkingVD->SetSeeds(num, begin); 00190 } 00192 00193 #endif 00194 00198 void SetSeeds(SeedsType & seeds) 00199 { 00200 m_NumberOfSeeds = seeds.size(); 00201 typename SeedsType::iterator it = seeds.begin(); 00202 m_WorkingVD->SetSeeds(m_NumberOfSeeds, it); 00203 } 00205 00207 PointType GetSeed(int SeedID) 00208 { return m_WorkingVD->GetSeed(SeedID); } 00209 00211 void DrawDiagram(VDImagePointer result, unsigned char incolor, 00212 unsigned char outcolor, unsigned char boundcolor); 00213 00214 void BeforeNextStep(void); 00215 00218 virtual void GenerateInputRequestedRegion(); 00219 00222 virtual void EnlargeOutputRequestedRegion(DataObject *output); 00223 00224 protected: 00225 VoronoiSegmentationImageFilterBase(); 00226 ~VoronoiSegmentationImageFilterBase(); 00227 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00228 00229 void GenerateData(void); //general pipeline function. 00230 00231 SizeType m_Size; 00232 int m_NumberOfSeeds; 00233 int m_MinRegion; 00234 int m_Steps; 00235 int m_LastStepSeeds; 00236 int m_NumberOfSeedsToAdded; 00237 int m_NumberOfBoundary; 00238 00239 std::vector< int > m_NumberOfPixels; 00240 std::vector< unsigned char > m_Label; 00241 00242 double m_MeanDeviation; 00243 bool m_UseBackgroundInAPrior; 00244 bool m_OutputBoundary; //if =1 then output the boundaries, if = 0 then 00245 // output the object. 00246 bool m_InteractiveSegmentation; 00247 00248 typename VoronoiDiagram::Pointer m_WorkingVD; 00249 00250 typename VoronoiDiagramGenerator::Pointer m_VDGenerator; 00251 00252 std::vector< PointType > m_SeedsToAdded; 00253 00254 // private methods: 00255 // Classify all the voronoi cells as interior , exterior or boundary. 00256 virtual void ClassifyDiagram(void); 00257 00258 // Generate the seeds to be added by dividing the boundary cells. 00259 virtual void GenerateAddingSeeds(void); 00260 00261 // Compute the statistics of the pixels inside the cell. 00262 void GetPixelIndexFromPolygon(PointTypeDeque VertList, IndexList *PixelPool); 00263 00264 virtual bool TestHomogeneity(IndexList &) 00265 { return 1; } 00266 00267 void FillPolygon(PointTypeDeque vertlist, OutputPixelType color = 1); 00268 00269 // Draw a straight line to the output image. 00270 void drawLine(PointType p1, PointType p2); 00271 00272 // Draw the intermedia Voronoi Diagram structure. 00273 void drawVDline(VDImagePointer result, PointType p1, PointType p2, unsigned char color); 00274 00275 private: 00276 VoronoiSegmentationImageFilterBase(const Self &); //purposely not implemented 00277 void operator=(const Self &); //purposely not implemented 00278 }; 00279 } //end namespace 00280 00281 #ifndef ITK_MANUAL_INSTANTIATION 00282 #include "itkVoronoiSegmentationImageFilterBase.hxx" 00283 #endif 00284 00285 #endif 00286