Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
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 
34 template<class TInputImage, class TOutputImage=otb::LabelMapWithAdjacency< itk::LabelObject< typename TInputImage::PixelType, TInputImage::ImageDimension > > >
36  public itk::ImageToImageFilter<TInputImage, TOutputImage>
37 {
38 public:
45 
47  typedef TInputImage InputImageType;
48  typedef TOutputImage OutputImageType;
49  typedef typename InputImageType::Pointer InputImagePointer;
50  typedef typename InputImageType::ConstPointer InputImageConstPointer;
51  typedef typename InputImageType::RegionType InputImageRegionType;
52  typedef typename InputImageType::PixelType InputImagePixelType;
53  typedef typename InputImageType::IndexType IndexType;
54 
55  typedef typename OutputImageType::Pointer OutputImagePointer;
56  typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
57  typedef typename OutputImageType::RegionType OutputImageRegionType;
58  typedef typename OutputImageType::PixelType OutputImagePixelType;
59  typedef typename OutputImageType::LabelObjectType LabelObjectType;
60  typedef typename OutputImageType::AdjacencyMapType AdjacencyMapType;
61  typedef typename OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType;
62  typedef typename OutputImageType::LabelType LabelType;
63 
65  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
66 
68  itkStaticConstMacro(InputImageDimension, unsigned int,
69  TInputImage::ImageDimension);
70  itkStaticConstMacro(OutputImageDimension, unsigned int,
71  TOutputImage::ImageDimension);
72 
74  itkNewMacro(Self);
75 
78  ImageToImageFilter);
79 
84  itkSetMacro(BackgroundValue, OutputImagePixelType);
85  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
86 
87 protected:
93  void PrintSelf(std::ostream& os, itk::Indent indent) const;
94 
95  // class to store a RLE
96  class RLE
97  {
98  public:
99  // Location
101  // Length
102  long unsigned int length;
103  // Label
104  unsigned long int label;
105  // Constructor
106  RLE(const IndexType & w, long unsigned int l, unsigned long int la)
107  {
108  where = w;
109  length = l;
110  label = la;
111  }
112 
113  }; // end class RLE
114 
115  // RLE Vector
116  typedef std::vector<RLE> RLEVectorType;
117 
121  void GenerateInputRequestedRegion();
122 
124  void EnlargeOutputRequestedRegion(itk::DataObject *itkNotUsed(output));
125 
126  virtual void BeforeThreadedGenerateData();
127 
128  virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId);
129 
130  virtual void AfterThreadedGenerateData();
131 
133  void AddAdjacency(LabelType label1, LabelType label2, itk::ThreadIdType threadId);
134 
136  void ParseLine(const RLEVectorType & line, itk::ThreadIdType threadId);
137 
139  void ParseConsecutiveLines(const RLEVectorType& line1, const RLEVectorType& line2, itk::ThreadIdType threadId);
140 
141 
142 private:
143  LabelImageToLabelMapWithAdjacencyFilter(const Self&); //purposely not implemented
144  void operator=(const Self&); //purposely not implemented
145 
147 
148  typename std::vector< OutputImagePointer > m_TemporaryImages;
149  typename std::vector<AdjacencyMapType> m_TemporaryAdjacencyMaps;
150 
151 }; // end of class
152 
153 } // end namespace otb
154 
155 #ifndef OTB_MANUAL_INSTANTIATION
157 #endif
158 
159 #endif
160 
161 
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
unsigned int ThreadIdType