itkBinaryImageToLabelMapFilter.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkBinaryImageToLabelMapFilter_h
00019 #define __itkBinaryImageToLabelMapFilter_h
00020
00021 #include "itkImageToImageFilter.h"
00022 #include "itkImage.h"
00023 #include "itkConceptChecking.h"
00024 #include <vector>
00025 #include <map>
00026 #include "itkProgressReporter.h"
00027 #include "itkBarrier.h"
00028
00029 namespace itk
00030 {
00031
00052 template <class TInputImage,
00053 class TOutputImage =
00054 LabelMap< LabelObject< unsigned long, ::itk::GetImageDimension<TInputImage>::ImageDimension> > >
00055 class ITK_EXPORT BinaryImageToLabelMapFilter :
00056 public ImageToImageFilter< TInputImage, TOutputImage >
00057 {
00058 public:
00062 typedef BinaryImageToLabelMapFilter Self;
00063 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00064 typedef SmartPointer<Self> Pointer;
00065 typedef SmartPointer<const Self> ConstPointer;
00066
00070 itkNewMacro(Self);
00071
00075 itkTypeMacro(BinaryImageToLabelMapFilter, ImageToImageFilter);
00076
00080 typedef typename Superclass::InputImagePointer InputImagePointer;
00081
00086 typedef typename TOutputImage::PixelType OutputPixelType;
00087 typedef typename TInputImage::PixelType InputPixelType;
00088 typedef typename TInputImage::SizeValueType SizeValueType;
00089 typedef typename TInputImage::OffsetValueType OffsetValueType;
00090 itkStaticConstMacro(ImageDimension, unsigned int, TOutputImage::ImageDimension);
00091 itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
00092 itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
00094
00098 typedef TInputImage InputImageType;
00099 typedef typename TInputImage::IndexType IndexType;
00100 typedef typename TInputImage::SizeType SizeType;
00101 typedef typename TInputImage::OffsetType OffsetType;
00102
00103 typedef TOutputImage OutputImageType;
00104 typedef typename TOutputImage::RegionType RegionType;
00105 typedef typename TOutputImage::IndexType OutputIndexType;
00106 typedef typename TOutputImage::SizeType OutputSizeType;
00107 typedef typename TOutputImage::OffsetType OutputOffsetType;
00108 typedef typename TOutputImage::PixelType OutputImagePixelType;
00109
00110 typedef std::list<IndexType> ListType;
00111
00118 itkSetMacro(FullyConnected, bool);
00119 itkGetConstReferenceMacro(FullyConnected, bool);
00120 itkBooleanMacro(FullyConnected);
00122
00123
00124 itkGetConstReferenceMacro( NumberOfObjects, unsigned long);
00125
00130 itkSetMacro(OutputBackgroundValue, OutputPixelType);
00131 itkGetConstMacro(OutputBackgroundValue, OutputPixelType);
00133
00138 itkSetMacro(InputForegroundValue, InputPixelType);
00139 itkGetConstMacro(InputForegroundValue, InputPixelType);
00141
00142
00143 #ifdef ITK_USE_CONCEPT_CHECKING
00144
00145 itkConceptMacro(SameDimension,
00146 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00147 itkGetStaticConstMacro(OutputImageDimension)>));
00148 #endif
00149
00150
00151 protected:
00152 BinaryImageToLabelMapFilter();
00153 virtual ~BinaryImageToLabelMapFilter() {}
00154 void PrintSelf(std::ostream& os, Indent indent) const;
00155
00159 void BeforeThreadedGenerateData ();
00160 void AfterThreadedGenerateData ();
00161 void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00163
00167 void GenerateInputRequestedRegion();
00168
00173 void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00174
00175 private:
00176 BinaryImageToLabelMapFilter(const Self&);
00177 void operator=(const Self&);
00178
00179
00180 typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00181
00182
00183 class runLength
00184 {
00185 public:
00186
00187 long int length;
00188 typename InputImageType::IndexType where;
00189 unsigned long int label;
00190 };
00191
00192 typedef std::vector<runLength> lineEncoding;
00193
00194
00195 typedef std::vector<lineEncoding> LineMapType;
00196
00197 typedef std::vector<long> OffsetVectorType;
00198
00199
00200 typedef std::vector<unsigned long int> UnionFindType;
00201 UnionFindType m_UnionFind;
00202 UnionFindType m_Consecutive;
00203
00204 void InitUnion(const unsigned long int size)
00205 {
00206 m_UnionFind = UnionFindType(size + 1);
00207 }
00208
00209 void InsertSet(const unsigned long int label);
00210 unsigned long int LookupSet(const unsigned long int label);
00211 void LinkLabels(const unsigned long int lab1, const unsigned long int lab2);
00212 unsigned long int CreateConsecutive();
00214 bool CheckNeighbors(const OutputIndexType &A,
00215 const OutputIndexType &B);
00216
00217 void CompareLines(lineEncoding ¤t, const lineEncoding &Neighbour);
00218
00219 void FillOutput(const LineMapType &LineMap,
00220 ProgressReporter &progress);
00221
00222 void SetupLineOffsets( OffsetVectorType & LineOffsets );
00223
00224 void Wait()
00225 {
00226
00227 if( m_NumberOfLabels.size() > 1 )
00228 {
00229 m_Barrier->Wait();
00230 }
00231 }
00232
00233 OutputPixelType m_OutputBackgroundValue;
00234 InputPixelType m_InputForegroundValue;
00235
00236 SizeValueType m_NumberOfObjects;
00237
00238 bool m_FullyConnected;
00239
00240 typename std::vector< SizeValueType > m_NumberOfLabels;
00241 typename std::vector< SizeValueType > m_FirstLineIdToJoin;
00242 typename Barrier::Pointer m_Barrier;
00243
00244 #if !defined(CABLE_CONFIGURATION)
00245 LineMapType m_LineMap;
00246 #endif
00247 };
00248
00249 }
00250
00251 #ifndef ITK_MANUAL_INSTANTIATION
00252 #if !defined(CABLE_CONFIGURATION)
00253 #include "itkBinaryImageToLabelMapFilter.txx"
00254 #endif
00255 #endif
00256
00257 #endif
00258