ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkBinaryStatisticsKeepNObjectsImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkBinaryStatisticsKeepNObjectsImageFilter_h
19 #define itkBinaryStatisticsKeepNObjectsImageFilter_h
20 
25 
26 namespace itk
27 {
45 template< typename TInputImage, typename TFeatureImage >
46 class ITK_TEMPLATE_EXPORT BinaryStatisticsKeepNObjectsImageFilter:
47  public ImageToImageFilter< TInputImage, TInputImage >
48 {
49 public:
50  ITK_DISALLOW_COPY_AND_ASSIGN(BinaryStatisticsKeepNObjectsImageFilter);
51 
57 
59  using InputImageType = TInputImage;
60  using OutputImageType = TInputImage;
61  using InputImagePointer = typename InputImageType::Pointer;
62  using InputImageConstPointer = typename InputImageType::ConstPointer;
64  using InputImagePixelType = typename InputImageType::PixelType;
65  using OutputImagePointer = typename OutputImageType::Pointer;
66  using OutputImageConstPointer = typename OutputImageType::ConstPointer;
68  using OutputImagePixelType = typename OutputImageType::PixelType;
69 
70  using FeatureImageType = TFeatureImage;
71  using FeatureImagePointer = typename FeatureImageType::Pointer;
72  using FeatureImageConstPointer = typename FeatureImageType::ConstPointer;
73  using FeatureImagePixelType = typename FeatureImageType::PixelType;
74 
76  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
77  static constexpr unsigned int OutputImageDimension = TInputImage::ImageDimension;
78  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
79 
81 
89 
91  itkNewMacro(Self);
92 
96 
103  itkSetMacro(FullyConnected, bool);
104  itkGetConstReferenceMacro(FullyConnected, bool);
105  itkBooleanMacro(FullyConnected);
107 
108 #ifdef ITK_USE_CONCEPT_CHECKING
109  // Begin concept checking
110  itkConceptMacro( InputEqualityComparableCheck,
112  itkConceptMacro( IntConvertibleToInputCheck,
114  itkConceptMacro( InputOStreamWritableCheck,
116  // End concept checking
117 #endif
118 
123  itkSetMacro(BackgroundValue, OutputImagePixelType);
124  itkGetConstMacro(BackgroundValue, OutputImagePixelType);
126 
131  itkSetMacro(ForegroundValue, OutputImagePixelType);
132  itkGetConstMacro(ForegroundValue, OutputImagePixelType);
134 
138  itkGetConstMacro(NumberOfObjects, SizeValueType);
139  itkSetMacro(NumberOfObjects, SizeValueType);
141 
147  itkGetConstMacro(ReverseOrdering, bool);
148  itkSetMacro(ReverseOrdering, bool);
149  itkBooleanMacro(ReverseOrdering);
151 
156  itkGetConstMacro(Attribute, AttributeType);
157  itkSetMacro(Attribute, AttributeType);
158  void SetAttribute(const std::string & s)
159  {
160  this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
161  }
163 
165  void SetFeatureImage(const TFeatureImage *input)
166  {
167  // Process object is not const-correct so the const casting is required.
168  this->SetNthInput( 1, const_cast< TFeatureImage * >( input ) );
169  }
170 
173  {
174  return static_cast< const FeatureImageType * >( this->ProcessObject::GetInput(1) );
175  }
176 
178  void SetInput1(const InputImageType *input)
179  {
180  this->SetInput(input);
181  }
182 
184  void SetInput2(const FeatureImageType *input)
185  {
186  this->SetFeatureImage(input);
187  }
188 
189 protected:
191  ~BinaryStatisticsKeepNObjectsImageFilter() override = default;
192  void PrintSelf(std::ostream & os, Indent indent) const override;
193 
197  void GenerateInputRequestedRegion() override;
198 
200  void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ) override;
201 
204  void GenerateData() override;
205 
206 private:
207  bool m_FullyConnected{false};
210  SizeValueType m_NumberOfObjects{0};
211  bool m_ReverseOrdering{false};
213 }; // end of class
214 } // end namespace itk
215 
216 #ifndef ITK_MANUAL_INSTANTIATION
217 #include "itkBinaryStatisticsKeepNObjectsImageFilter.hxx"
218 #endif
219 
220 #endif
Light weight base class for most itk classes.
typename Superclass::AttributeType AttributeType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
A Label object to store the common attributes related to the statistics of the object.
keep N objects according to their statistics attributes
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
keep N objects according to their statistics attributes
Label the connected components in a binary image and produce a collection of label objects...
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Templated n-dimensional image to store labeled objects.
Definition: itkLabelMap.h:70
The valuator class for the StatisticsLabelObject.
#define itkConceptMacro(name, concept)
Base class for all data objects in ITK.
Convert a LabelMap to a binary image.