OTB  9.0.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-2022 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 {
31 
38 template <class TInputImage, class TOutputImage = otb::LabelMapWithAdjacency<itk::LabelObject<typename TInputImage::PixelType, TInputImage::ImageDimension>>>
39 class ITK_EXPORT LabelImageToLabelMapWithAdjacencyFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
40 {
41 public:
44  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
45  typedef itk::SmartPointer<Self> Pointer;
46  typedef itk::SmartPointer<const Self> ConstPointer;
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, TInputImage::ImageDimension);
71  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
73 
75  itkNewMacro(Self);
76 
78  itkTypeMacro(LabelImageToLabelMapWithAdjacencyFilter, ImageToImageFilter);
79 
84  itkSetMacro(BackgroundValue, OutputImagePixelType);
85  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
87 
88 protected:
91 
94 
96  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
97 
98  // class to store a RLE
99  class RLE
100  {
101  public:
102  // Location
104  // Length
105  long unsigned int length;
106  // Label
107  unsigned long int label;
108  // Constructor
109  RLE(const IndexType& w, long unsigned int l, unsigned long int la)
110  {
111  where = w;
112  length = l;
113  label = la;
114  }
115 
116  }; // end class RLE
117 
118  // RLE Vector
119  typedef std::vector<RLE> RLEVectorType;
120 
124  void GenerateInputRequestedRegion() override;
125 
127  void EnlargeOutputRequestedRegion(itk::DataObject* itkNotUsed(output)) override;
128 
129  void BeforeThreadedGenerateData() override;
130 
131  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
132 
133  void AfterThreadedGenerateData() override;
134 
136  void AddAdjacency(LabelType label1, LabelType label2, itk::ThreadIdType threadId);
137 
139  void ParseLine(const RLEVectorType& line, itk::ThreadIdType threadId);
140 
142  void ParseConsecutiveLines(const RLEVectorType& line1, const RLEVectorType& line2, itk::ThreadIdType threadId);
143 
144 
145 private:
147  void operator=(const Self&) = delete;
148 
150 
151  typename std::vector<OutputImagePointer> m_TemporaryImages;
152  typename std::vector<AdjacencyMapType> m_TemporaryAdjacencyMaps;
153 
154 }; // end of class
155 
156 } // end namespace otb
157 
158 #ifndef OTB_MANUAL_INSTANTIATION
160 #endif
161 
162 #endif
otb::LabelImageToLabelMapWithAdjacencyFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:59
otb::LabelImageToLabelMapWithAdjacencyFilter::RLE::where
IndexType where
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:103
otb::LabelImageToLabelMapWithAdjacencyFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:53
otb::LabelImageToLabelMapWithAdjacencyFilter::RLEVectorType
std::vector< RLE > RLEVectorType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:119
otb::LabelImageToLabelMapWithAdjacencyFilter::InputImageConstPointer
InputImageType::ConstPointer InputImageConstPointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:52
otb::LabelImageToLabelMapWithAdjacencyFilter::RLE::label
unsigned long int label
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:107
otbLabelMapWithAdjacency.h
otb::LabelImageToLabelMapWithAdjacencyFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:50
otb::LabelImageToLabelMapWithAdjacencyFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:46
otb::LabelImageToLabelMapWithAdjacencyFilter::~LabelImageToLabelMapWithAdjacencyFilter
~LabelImageToLabelMapWithAdjacencyFilter() override
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:93
otb::LabelImageToLabelMapWithAdjacencyFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:45
otb::LabelImageToLabelMapWithAdjacencyFilter::AdjacencyMapType
OutputImageType::AdjacencyMapType AdjacencyMapType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:62
otb::LabelImageToLabelMapWithAdjacencyFilter::m_TemporaryImages
std::vector< OutputImagePointer > m_TemporaryImages
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:151
otb::LabelImageToLabelMapWithAdjacencyFilter::m_TemporaryAdjacencyMaps
std::vector< AdjacencyMapType > m_TemporaryAdjacencyMaps
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:152
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LabelImageToLabelMapWithAdjacencyFilter
convert a labeled image to a label map with adjacency information.
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:39
otb::LabelImageToLabelMapWithAdjacencyFilter::IndexType
InputImageType::IndexType IndexType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:55
otb::LabelImageToLabelMapWithAdjacencyFilter::InputImageType
TInputImage InputImageType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:49
otb::LabelImageToLabelMapWithAdjacencyFilter::LabelType
OutputImageType::LabelType LabelType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:64
otb::LabelImageToLabelMapWithAdjacencyFilter::LabelObjectType
OutputImageType::LabelObjectType LabelObjectType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:61
otb::LabelImageToLabelMapWithAdjacencyFilter::OutputImageConstPointer
OutputImageType::ConstPointer OutputImageConstPointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:58
otb::LabelImageToLabelMapWithAdjacencyFilter::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:54
otb::LabelImageToLabelMapWithAdjacencyFilter::RLE::length
long unsigned int length
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:105
otb::LabelImageToLabelMapWithAdjacencyFilter::Self
LabelImageToLabelMapWithAdjacencyFilter Self
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:43
otb::LabelImageToLabelMapWithAdjacencyFilter::RLE::RLE
RLE(const IndexType &w, long unsigned int l, unsigned long int la)
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:109
otb::LabelImageToLabelMapWithAdjacencyFilter::AdjacentLabelsContainerType
OutputImageType::AdjacentLabelsContainerType AdjacentLabelsContainerType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:63
otb::LabelImageToLabelMapWithAdjacencyFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:60
otb::LabelImageToLabelMapWithAdjacencyFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:44
otb::LabelImageToLabelMapWithAdjacencyFilter::ConstLineIteratorType
LabelObjectType::ConstLineIterator ConstLineIteratorType
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:67
otb::LabelImageToLabelMapWithAdjacencyFilter::m_BackgroundValue
OutputImagePixelType m_BackgroundValue
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:149
otb::LabelImageToLabelMapWithAdjacencyFilter::RLE
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:99
otb::LabelImageToLabelMapWithAdjacencyFilter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:57
otbLabelImageToLabelMapWithAdjacencyFilter.hxx
otb::LabelImageToLabelMapWithAdjacencyFilter::InputImagePointer
InputImageType::Pointer InputImagePointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:51