OTB  6.1.0
Orfeo Toolbox
otbLabelImageToLabelMapWithAdjacencyFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbLabelImageToLabelMapWithAdjacencyFilter_h
23 #define otbLabelImageToLabelMapWithAdjacencyFilter_h
24 
25 #include "itkImageToImageFilter.h"
27 #include "itkLabelObject.h"
28 
29 namespace otb {
30 
37 template<class TInputImage, class TOutputImage=otb::LabelMapWithAdjacency< itk::LabelObject< typename TInputImage::PixelType, TInputImage::ImageDimension > > >
39  public itk::ImageToImageFilter<TInputImage, TOutputImage>
40 {
41 public:
48 
50  typedef TInputImage InputImageType;
51  typedef TOutputImage OutputImageType;
52  typedef typename InputImageType::Pointer InputImagePointer;
53  typedef typename InputImageType::ConstPointer InputImageConstPointer;
54  typedef typename InputImageType::RegionType InputImageRegionType;
55  typedef typename InputImageType::PixelType InputImagePixelType;
57 
58  typedef typename OutputImageType::Pointer OutputImagePointer;
59  typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
60  typedef typename OutputImageType::RegionType OutputImageRegionType;
61  typedef typename OutputImageType::PixelType OutputImagePixelType;
62  typedef typename OutputImageType::LabelObjectType LabelObjectType;
63  typedef typename OutputImageType::AdjacencyMapType AdjacencyMapType;
64  typedef typename OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType;
65  typedef typename OutputImageType::LabelType LabelType;
66 
68  typedef typename LabelObjectType::ConstLineIterator ConstLineIteratorType;
69 
71  itkStaticConstMacro(InputImageDimension, unsigned int,
72  TInputImage::ImageDimension);
73  itkStaticConstMacro(OutputImageDimension, unsigned int,
74  TOutputImage::ImageDimension);
76 
78  itkNewMacro(Self);
79 
82  ImageToImageFilter);
83 
88  itkSetMacro(BackgroundValue, OutputImagePixelType);
89  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
91 
92 protected:
95 
98 
100  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE;
101 
102  // class to store a RLE
103  class RLE
104  {
105  public:
106  // Location
108  // Length
109  long unsigned int length;
110  // Label
111  unsigned long int label;
112  // Constructor
113  RLE(const IndexType & w, long unsigned int l, unsigned long int la)
114  {
115  where = w;
116  length = l;
117  label = la;
118  }
119 
120  }; // end class RLE
121 
122  // RLE Vector
123  typedef std::vector<RLE> RLEVectorType;
124 
128  void GenerateInputRequestedRegion() ITK_OVERRIDE;
129 
131  void EnlargeOutputRequestedRegion(itk::DataObject *itkNotUsed(output)) ITK_OVERRIDE;
132 
133  void BeforeThreadedGenerateData() ITK_OVERRIDE;
134 
135  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) ITK_OVERRIDE;
136 
137  void AfterThreadedGenerateData() ITK_OVERRIDE;
138 
140  void AddAdjacency(LabelType label1, LabelType label2, itk::ThreadIdType threadId);
141 
143  void ParseLine(const RLEVectorType & line, itk::ThreadIdType threadId);
144 
146  void ParseConsecutiveLines(const RLEVectorType& line1, const RLEVectorType& line2, itk::ThreadIdType threadId);
147 
148 
149 private:
150  LabelImageToLabelMapWithAdjacencyFilter(const Self&); //purposely not implemented
151  void operator=(const Self&); //purposely not implemented
152 
153  OutputImagePixelType m_BackgroundValue;
154 
155  typename std::vector< OutputImagePointer > m_TemporaryImages;
156  typename std::vector<AdjacencyMapType> m_TemporaryAdjacencyMaps;
157 
158 }; // end of class
159 
160 } // end namespace otb
161 
162 #ifndef OTB_MANUAL_INSTANTIATION
164 #endif
165 
166 #endif
167 
168 
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
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:142
OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType
OutputImageType::PixelType OutputImagePixelType
unsigned int ThreadIdType
OutputImageType::RegionType OutputImageRegionType