OTB  5.0.0
Orfeo Toolbox
otbLabelImageToLabelMapWithAdjacencyFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbLabelImageToLabelMapWithAdjacencyFilter_h
22 #define __otbLabelImageToLabelMapWithAdjacencyFilter_h
23 
24 #include "itkImageToImageFilter.h"
26 #include "itkLabelObject.h"
27 
28 namespace otb {
29 
36 template<class TInputImage, class TOutputImage=otb::LabelMapWithAdjacency< itk::LabelObject< typename TInputImage::PixelType, TInputImage::ImageDimension > > >
38  public itk::ImageToImageFilter<TInputImage, TOutputImage>
39 {
40 public:
47 
49  typedef TInputImage InputImageType;
50  typedef TOutputImage OutputImageType;
51  typedef typename InputImageType::Pointer InputImagePointer;
52  typedef typename InputImageType::ConstPointer InputImageConstPointer;
53  typedef typename InputImageType::RegionType InputImageRegionType;
54  typedef typename InputImageType::PixelType InputImagePixelType;
55  typedef typename InputImageType::IndexType IndexType;
56 
57  typedef typename OutputImageType::Pointer OutputImagePointer;
58  typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
59  typedef typename OutputImageType::RegionType OutputImageRegionType;
60  typedef typename OutputImageType::PixelType OutputImagePixelType;
61  typedef typename OutputImageType::LabelObjectType LabelObjectType;
62  typedef typename OutputImageType::AdjacencyMapType AdjacencyMapType;
63  typedef typename OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType;
64  typedef typename OutputImageType::LabelType LabelType;
65 
67  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
68 
70  itkStaticConstMacro(InputImageDimension, unsigned int,
71  TInputImage::ImageDimension);
72  itkStaticConstMacro(OutputImageDimension, unsigned int,
73  TOutputImage::ImageDimension);
75 
77  itkNewMacro(Self);
78 
81  ImageToImageFilter);
82 
87  itkSetMacro(BackgroundValue, OutputImagePixelType);
88  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
90 
91 protected:
94 
97 
99  void PrintSelf(std::ostream& os, itk::Indent indent) const;
100 
101  // class to store a RLE
102  class RLE
103  {
104  public:
105  // Location
107  // Length
108  long unsigned int length;
109  // Label
110  unsigned long int label;
111  // Constructor
112  RLE(const IndexType & w, long unsigned int l, unsigned long int la)
113  {
114  where = w;
115  length = l;
116  label = la;
117  }
118 
119  }; // end class RLE
120 
121  // RLE Vector
122  typedef std::vector<RLE> RLEVectorType;
123 
127  void GenerateInputRequestedRegion();
128 
130  void EnlargeOutputRequestedRegion(itk::DataObject *itkNotUsed(output));
131 
132  virtual void BeforeThreadedGenerateData();
133 
134  virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId);
135 
136  virtual void AfterThreadedGenerateData();
137 
139  void AddAdjacency(LabelType label1, LabelType label2, itk::ThreadIdType threadId);
140 
142  void ParseLine(const RLEVectorType & line, itk::ThreadIdType threadId);
143 
145  void ParseConsecutiveLines(const RLEVectorType& line1, const RLEVectorType& line2, itk::ThreadIdType threadId);
146 
147 
148 private:
149  LabelImageToLabelMapWithAdjacencyFilter(const Self&); //purposely not implemented
150  void operator=(const Self&); //purposely not implemented
151 
153 
154  typename std::vector< OutputImagePointer > m_TemporaryImages;
155  typename std::vector<AdjacencyMapType> m_TemporaryAdjacencyMaps;
156 
157 }; // end of class
158 
159 } // end namespace otb
160 
161 #ifndef OTB_MANUAL_INSTANTIATION
163 #endif
164 
165 #endif
166 
167 
convert a labeled image to a label map with adjacency information.
RLE(const IndexType &w, long unsigned int l, unsigned long int la)
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType
OutputImageType::PixelType OutputImagePixelType
OutputImageType::RegionType OutputImageRegionType
unsigned int ThreadIdType