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 #include "itkLabelMap.h"
00029 #include "itkLabelObject.h"
00030
00031 namespace itk
00032 {
00033
00054 template <class TInputImage,
00055 class TOutputImage =
00056 LabelMap< LabelObject< unsigned long, ::itk::GetImageDimension<TInputImage>::ImageDimension> > >
00057 class ITK_EXPORT BinaryImageToLabelMapFilter :
00058 public ImageToImageFilter< TInputImage, TOutputImage >
00059 {
00060 public:
00064 typedef BinaryImageToLabelMapFilter Self;
00065 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00066 typedef SmartPointer<Self> Pointer;
00067 typedef SmartPointer<const Self> ConstPointer;
00068
00072 itkNewMacro(Self);
00073
00077 itkTypeMacro(BinaryImageToLabelMapFilter, ImageToImageFilter);
00078
00082 typedef typename Superclass::InputImagePointer InputImagePointer;
00083
00088 typedef typename TOutputImage::PixelType OutputPixelType;
00089 typedef typename TInputImage::PixelType InputPixelType;
00090 typedef typename TInputImage::SizeValueType SizeValueType;
00091 typedef typename TInputImage::OffsetValueType OffsetValueType;
00092 itkStaticConstMacro(ImageDimension, unsigned int, TOutputImage::ImageDimension);
00093 itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
00094 itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
00096
00100 typedef TInputImage InputImageType;
00101 typedef typename TInputImage::IndexType IndexType;
00102 typedef typename TInputImage::SizeType SizeType;
00103 typedef typename TInputImage::OffsetType OffsetType;
00104
00105 typedef TOutputImage OutputImageType;
00106 typedef typename TOutputImage::RegionType RegionType;
00107 typedef typename TOutputImage::IndexType OutputIndexType;
00108 typedef typename TOutputImage::SizeType OutputSizeType;
00109 typedef typename TOutputImage::OffsetType OutputOffsetType;
00110 typedef typename TOutputImage::PixelType OutputImagePixelType;
00111
00112 typedef std::list<IndexType> ListType;
00113
00120 itkSetMacro(FullyConnected, bool);
00121 itkGetConstReferenceMacro(FullyConnected, bool);
00122 itkBooleanMacro(FullyConnected);
00124
00125
00126 itkGetConstReferenceMacro( NumberOfObjects, unsigned long);
00127
00132 itkSetMacro(OutputBackgroundValue, OutputPixelType);
00133 itkGetConstMacro(OutputBackgroundValue, OutputPixelType);
00135
00140 itkSetMacro(InputForegroundValue, InputPixelType);
00141 itkGetConstMacro(InputForegroundValue, InputPixelType);
00143
00144
00145 #ifdef ITK_USE_CONCEPT_CHECKING
00146
00147 itkConceptMacro(SameDimension,
00148 (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension),
00149 itkGetStaticConstMacro(OutputImageDimension)>));
00150 #endif
00151
00152
00153 protected:
00154 BinaryImageToLabelMapFilter();
00155 virtual ~BinaryImageToLabelMapFilter() {}
00156 void PrintSelf(std::ostream& os, Indent indent) const;
00157
00161 void BeforeThreadedGenerateData ();
00162 void AfterThreadedGenerateData ();
00163 void ThreadedGenerateData (const RegionType& outputRegionForThread, int threadId);
00165
00169 void GenerateInputRequestedRegion();
00170
00175 void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00176
00177 private:
00178 BinaryImageToLabelMapFilter(const Self&);
00179 void operator=(const Self&);
00180
00181
00182 typedef typename TOutputImage::RegionType::SizeType OutSizeType;
00183
00184
00185 class runLength
00186 {
00187 public:
00188
00189 long int length;
00190 typename InputImageType::IndexType where;
00191 unsigned long int label;
00192 };
00193
00194 typedef std::vector<runLength> lineEncoding;
00195
00196
00197 typedef std::vector<lineEncoding> LineMapType;
00198
00199 typedef std::vector<long> OffsetVectorType;
00200
00201
00202 typedef std::vector<unsigned long int> UnionFindType;
00203 UnionFindType m_UnionFind;
00204 UnionFindType m_Consecutive;
00205
00206 void InitUnion(const unsigned long int size)
00207 {
00208 m_UnionFind = UnionFindType(size + 1);
00209 }
00210
00211 void InsertSet(const unsigned long int label);
00212 unsigned long int LookupSet(const unsigned long int label);
00213 void LinkLabels(const unsigned long int lab1, const unsigned long int lab2);
00214 unsigned long int CreateConsecutive();
00216 bool CheckNeighbors(const OutputIndexType &A,
00217 const OutputIndexType &B);
00218
00219 void CompareLines(lineEncoding ¤t, const lineEncoding &Neighbour);
00220
00221 void FillOutput(const LineMapType &LineMap,
00222 ProgressReporter &progress);
00223
00224 void SetupLineOffsets( OffsetVectorType & LineOffsets );
00225
00226 void Wait()
00227 {
00228
00229 if( m_NumberOfLabels.size() > 1 )
00230 {
00231 m_Barrier->Wait();
00232 }
00233 }
00234
00235 OutputPixelType m_OutputBackgroundValue;
00236 InputPixelType m_InputForegroundValue;
00237
00238 SizeValueType m_NumberOfObjects;
00239
00240 bool m_FullyConnected;
00241
00242 typename std::vector< SizeValueType > m_NumberOfLabels;
00243 typename std::vector< SizeValueType > m_FirstLineIdToJoin;
00244 typename Barrier::Pointer m_Barrier;
00245
00246 #if !defined(CABLE_CONFIGURATION)
00247 LineMapType m_LineMap;
00248 #endif
00249 };
00250
00251 }
00252
00253 #ifndef ITK_MANUAL_INSTANTIATION
00254 #if !defined(CABLE_CONFIGURATION)
00255 #include "itkBinaryImageToLabelMapFilter.txx"
00256 #endif
00257 #endif
00258
00259 #endif
00260