ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkRelabelComponentImageFilter.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 itkRelabelComponentImageFilter_h
19 #define itkRelabelComponentImageFilter_h
20 
21 #include "itkInPlaceImageFilter.h"
22 #include "itkImage.h"
23 #include <vector>
24 
25 namespace itk
26 {
80 template< typename TInputImage, typename TOutputImage >
82  public InPlaceImageFilter< TInputImage, TOutputImage >
83 {
84 public:
90 
95 
100  typedef typename TOutputImage::PixelType OutputPixelType;
101  typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
102  typedef typename TInputImage::PixelType InputPixelType;
103  typedef typename TInputImage::InternalPixelType InputInternalPixelType;
104  itkStaticConstMacro(ImageDimension, unsigned int,
105  TOutputImage::ImageDimension);
106  itkStaticConstMacro(InputImageDimension, unsigned int,
107  TInputImage::ImageDimension);
109 
113  typedef TInputImage InputImageType;
114  typedef TOutputImage OutputImageType;
115  typedef typename TInputImage::IndexType IndexType;
116  typedef typename TInputImage::SizeType SizeType;
117  typedef typename TOutputImage::RegionType RegionType;
118 
124 
129 
133  itkNewMacro(Self);
134 
136  typedef IdentifierType LabelType;
137 
140 
143  itkGetConstMacro(NumberOfObjects, LabelType);
144 
145  typedef std::vector< ObjectSizeType > ObjectSizeInPixelsContainerType;
146  typedef std::vector< float > ObjectSizeInPhysicalUnitsContainerType;
147 
153  itkGetConstMacro(OriginalNumberOfObjects, LabelType);
154 
157  itkSetMacro(NumberOfObjectsToPrint, LabelType);
158  itkGetConstReferenceMacro(NumberOfObjectsToPrint, LabelType);
160 
167  itkSetMacro(MinimumObjectSize, ObjectSizeType);
168 
174  itkGetConstMacro(MinimumObjectSize, ObjectSizeType);
175 
178  itkSetMacro(SortByObjectSize, bool);
179  itkGetConstMacro(SortByObjectSize, bool);
180  itkBooleanMacro(SortByObjectSize);
182 
189  {
190  // The GetConstReferenceMacro can't be used here becase this container
191  // doesn't have an ostream<< operator overloaded.
192  return this->m_SizeOfObjectsInPixels;
193  }
194 
201  {
202  // The GetConstReferenceMacro can't be used here becase this container
203  // doesn't have an ostream<< operator overloaded.
204  return this->m_SizeOfObjectsInPhysicalUnits;
205  }
206 
211  {
212  if ( obj > 0 && obj <= m_NumberOfObjects )
213  {
214  return m_SizeOfObjectsInPixels[obj - 1];
215  }
216  else
217  {
218  return 0;
219  }
220  }
222 
227  {
228  if ( obj > 0 && obj <= m_NumberOfObjects )
229  {
230  return m_SizeOfObjectsInPhysicalUnits[obj - 1];
231  }
232  else
233  {
234  return 0;
235  }
236  }
238 
239 #ifdef ITK_USE_CONCEPT_CHECKING
240  // Begin concept checking
241  itkConceptMacro( InputEqualityComparableCheck,
243  itkConceptMacro( UnsignedLongConvertibleToInputCheck,
245  itkConceptMacro( OutputLongConvertibleToUnsignedLongCheck,
247  itkConceptMacro( InputConvertibleToOutputCheck,
249  itkConceptMacro( SameDimensionCheck,
251  // End concept checking
252 #endif
253 
254 protected:
255 
259  m_SortByObjectSize(true)
260  { this->InPlaceOff(); }
262 
266  void GenerateData() ITK_OVERRIDE;
267 
271  void GenerateInputRequestedRegion() ITK_OVERRIDE;
272 
274  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
275 
280  };
281 
282  // put the function objects here for sorting in descending order
284  {
285  public:
287  const RelabelComponentObjectType & b)
288  {
289  if ( a.m_SizeInPixels > b.m_SizeInPixels )
290  {
291  return true;
292  }
293  else if ( a.m_SizeInPixels < b.m_SizeInPixels )
294  {
295  return false;
296  }
297  // size in pixels and physical units are the same, sort based on
298  // original object number
299  else if ( a.m_ObjectNumber < b.m_ObjectNumber )
300  {
301  return true;
302  }
303  else
304  {
305  return false;
306  }
307  }
308  };
309 
310 private:
311  RelabelComponentImageFilter(const Self &) ITK_DELETE_FUNCTION;
312  void operator=(const Self &) ITK_DELETE_FUNCTION;
313 
319 
322 };
323 } // end namespace itk
324 
325 #ifndef ITK_MANUAL_INSTANTIATION
326 #include "itkRelabelComponentImageFilter.hxx"
327 #endif
328 
329 #endif
const ObjectSizeInPixelsContainerType & GetSizeOfObjectsInPixels() const
Superclass::InputImagePointer InputImagePointer
ObjectSizeInPhysicalUnitsContainerType m_SizeOfObjectsInPhysicalUnits
std::vector< ObjectSizeType > ObjectSizeInPixelsContainerType
virtual void InPlaceOff()
void GenerateInputRequestedRegion() override
void PrintSelf(std::ostream &os, Indent indent) const override
Base class for all process objects that output image data.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
bool operator()(const RelabelComponentObjectType &a, const RelabelComponentObjectType &b)
ObjectSizeType GetSizeOfObjectInPixels(LabelType obj) const
float GetSizeOfObjectInPhysicalUnits(LabelType obj) const
InputImageType::Pointer InputImagePointer
Relabel the components in an image such that consecutive labels are used.
const ObjectSizeInPhysicalUnitsContainerType & GetSizeOfObjectsInPhysicalUnits() const
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
TInputImage::InternalPixelType InputInternalPixelType
Base class for filters that take an image as input and overwrite that image as the output...
#define itkConceptMacro(name, concept)
TOutputImage::InternalPixelType OutputInternalPixelType
ObjectSizeInPixelsContainerType m_SizeOfObjectsInPixels
InPlaceImageFilter< TInputImage, TOutputImage > Superclass