OTB  10.0.0
Orfeo Toolbox
otbLabelImageRegionPruningFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbLabelImageRegionPruningFilter_h
22 #define otbLabelImageRegionPruningFilter_h
23 
24 #include "otbImage.h"
25 #include "otbVectorImage.h"
26 #include "itkImageToImageFilter.h"
27 #include "itkNumericTraits.h"
28 
29 #include <set>
30 
31 namespace otb
32 {
33 
45 template <class TInputLabelImage, class TInputSpectralImage, class TOutputLabelImage = TInputLabelImage, class TOutputClusteredImage = TInputSpectralImage>
46 class ITK_EXPORT LabelImageRegionPruningFilter : public itk::ImageToImageFilter<TInputLabelImage, TOutputLabelImage>
47 {
48 public:
51  typedef itk::ImageToImageFilter<TInputLabelImage, TOutputLabelImage> Superclass;
52  typedef itk::SmartPointer<Self> Pointer;
53  typedef itk::SmartPointer<const Self> ConstPointer;
54  typedef double RealType;
55 
57  itkTypeMacro(LabelImageRegionPruningFilter, ImageToImageFilter);
58  itkNewMacro(Self);
60 
62  typedef TInputLabelImage InputLabelImageType;
63  typedef typename InputLabelImageType::PixelType InputLabelType;
64 
65  typedef TInputLabelImage InputImageType;
66  typedef typename InputImageType::Pointer InputImagePointerType;
67  typedef typename InputImageType::PixelType InputPixelType;
68  typedef typename InputImageType::IndexType InputIndexType;
69  typedef typename InputImageType::SizeType InputSizeType;
70  typedef typename InputImageType::IndexValueType InputIndexValueType;
71  typedef typename InputImageType::PointType PointType;
72  typedef typename InputImageType::RegionType RegionType;
73  typedef typename InputImageType::SizeType SizeType;
74 
75  typedef TInputSpectralImage InputSpectralImageType;
76  typedef typename TInputSpectralImage::PixelType SpectralPixelType;
77 
78  typedef TOutputLabelImage OutputLabelImageType;
79  typedef typename OutputLabelImageType::PixelType OutputLabelType;
80 
81  typedef TOutputLabelImage OutputImageType;
82  typedef typename OutputImageType::Pointer OutputImagePointerType;
83  typedef typename OutputImageType::PixelType OutputPixelType;
84  typedef typename OutputImageType::RegionType OutputRegionType;
85 
86  typedef TOutputClusteredImage OutputClusteredImageType;
87 
88  itkStaticConstMacro(ImageDimension, unsigned int, InputLabelImageType::ImageDimension);
89 
92  typedef std::set<LabelType> AdjacentLabelsContainerType;
93  typedef std::vector<AdjacentLabelsContainerType> RegionAdjacencyMapType;
94 
95  itkSetMacro(MinRegionSize, RealType);
96  itkGetConstMacro(MinRegionSize, RealType);
97 
99  const OutputLabelImageType* GetLabelOutput() const;
100 
102  OutputLabelImageType* GetLabelOutput();
103 
105  const OutputClusteredImageType* GetClusteredOutput() const;
106 
108  OutputClusteredImageType* GetClusteredOutput();
109 
111  void SetInputLabelImage(const InputLabelImageType* labelImage);
112 
114  void SetInputSpectralImage(const InputSpectralImageType* spectralImage);
115 
117  InputLabelImageType* GetInputLabelImage();
118 
120  InputSpectralImageType* GetInputSpectralImage();
121 
122 protected:
123  void EnlargeOutputRequestedRegion(itk::DataObject* output) override;
124 
125  void GenerateOutputInformation(void) override;
126 
127  void GenerateData() override;
128 
131 
133  ~LabelImageRegionPruningFilter() override;
134 
136  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
137 
139  RegionAdjacencyMapType LabelImageToRegionAdjacencyMap(typename OutputLabelImageType::Pointer inputLabelImage);
140 
141 private:
143  void operator=(const Self&) = delete;
144 
147  unsigned int m_MinRegionSize;
148 
150  std::vector<LabelType> m_CanonicalLabels;
151 
153  std::vector<SpectralPixelType> m_Modes;
154 
156  std::vector<unsigned int> m_PointCounts;
157 };
158 
159 } // end namespace otb
160 
161 #ifndef OTB_MANUAL_INSTANTIATION
163 #endif
164 
165 #endif
std::vector< AdjacentLabelsContainerType > RegionAdjacencyMapType
TInputSpectralImage::PixelType SpectralPixelType
LabelImageRegionPruningFilter(const Self &)=delete
itk::ImageToImageFilter< TInputLabelImage, TOutputLabelImage > Superclass
InputImageType::IndexValueType InputIndexValueType
OutputLabelImageType::PixelType OutputLabelType
void operator=(const Self &)=delete
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.