Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkMorphologicalContourInterpolator.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 itkMorphologicalContourInterpolator_h
19 #define itkMorphologicalContourInterpolator_h
20 
21 #include "itkBinaryThresholdImageFilter.h"
22 #include "itkConnectedComponentImageFilter.h"
23 #include "itkExtractImageFilter.h"
24 #include "itkImageToImageFilter.h"
25 #include "itksys/hash_map.hxx"
26 
27 namespace itk
28 {
64 template< typename TImage >
66  public ImageToImageFilter< TImage, TImage >
67 {
68  template< typename T >
70 
71 public:
73 
76  using Superclass = ImageToImageFilter< TImage, TImage >;
77  using Pointer = SmartPointer< Self >;
78  using SliceType = Image< typename TImage::PixelType, TImage::ImageDimension - 1 >;
79 
81  itkNewMacro( Self );
82 
84  itkTypeMacro( MorphologicalContourInterpolator, ImageToImageFilter );
85 
87  itkSetMacro( Label, typename TImage::PixelType );
88 
90  itkGetMacro( Label, typename TImage::PixelType );
91 
93  itkGetConstMacro( Label, typename TImage::PixelType );
94 
96  itkSetMacro( Axis, int );
97 
99  itkGetMacro( Axis, int );
100 
102  itkGetConstMacro( Axis, int );
103 
106  itkSetMacro( HeuristicAlignment, bool );
107 
110  itkGetMacro( HeuristicAlignment, bool );
111 
114  itkGetConstMacro( HeuristicAlignment, bool );
115 
119  itkSetMacro( UseDistanceTransform, bool );
120 
124  itkGetMacro( UseDistanceTransform, bool );
125 
129  itkGetConstMacro( UseDistanceTransform, bool );
130 
133  itkSetMacro( UseCustomSlicePositions, bool );
134 
137  itkGetMacro( UseCustomSlicePositions, bool );
138 
141  itkGetConstMacro( UseCustomSlicePositions, bool );
142 
144  void
146  {
147  if ( useBall != m_UseBallStructuringElement )
148  {
149  m_UseBallStructuringElement = useBall;
150  m_ConnectedComponents->SetFullyConnected( useBall );
151  this->Modified();
152  }
153  }
154 
156  itkGetMacro( UseBallStructuringElement, bool );
157 
159  itkGetConstMacro( UseBallStructuringElement, bool );
160 
165  void
167 
169  using SliceSetType = std::set< typename TImage::IndexValueType >;
170 
172  void
174  {
175  m_LabeledSlices.clear();
176  m_LabeledSlices.resize( TImage::ImageDimension );
177  this->Modified();
178  }
179 
182  void
183  SetLabeledSliceIndices( unsigned int axis,
184  typename TImage::PixelType label,
185  const std::vector< typename TImage::IndexValueType >& indices )
186  {
187  SliceSetType sliceSet;
188  sliceSet.insert( indices.begin(), indices.end() );
189  m_LabeledSlices[axis][label] = sliceSet;
190  this->Modified();
191  }
192 
195  void
196  SetLabeledSliceIndices( unsigned int axis, typename TImage::PixelType label, const SliceSetType& indices )
197  {
198  m_LabeledSlices[axis][label] = indices;
199  this->Modified();
200  }
201 
204  GetLabeledSliceIndices( unsigned int axis, typename TImage::PixelType label )
205  {
206  return m_LabeledSlices[axis][label];
207  }
208 
209  // each label gets a set of slices in which it is present
210  using LabeledSlicesType = itksys::hash_map< typename TImage::PixelType, SliceSetType >;
211  using SliceIndicesType = std::vector< LabeledSlicesType >;
212 
216  {
217  return m_LabeledSlices;
218  }
219 
220 protected:
222  ~MorphologicalContourInterpolator() override = default;
223  typename TImage::PixelType m_Label;
224  int m_Axis{ -1 };
225  bool m_HeuristicAlignment{ true };
229  IdentifierType m_MinAlignIters; // minimum number of iterations in align method
230  IdentifierType m_MaxAlignIters; // maximum number of iterations in align method
231  IdentifierType m_ThreadCount; // for thread local instances
232  SliceIndicesType m_LabeledSlices; // one for each axis
233 
235  using BoolImageType = Image< bool, TImage::ImageDimension >;
236  using FloatSliceType = Image< float, TImage::ImageDimension - 1 >;
237  using BoolSliceType = Image< bool, TImage::ImageDimension - 1 >;
238 
240  bool
241  ImagesEqual( typename BoolSliceType::Pointer& a, typename BoolSliceType::Pointer& b );
242 
244  void
245  GenerateData() override;
246 
248  void
249  InterpolateBetweenTwo( int axis,
250  TImage* out,
251  typename TImage::PixelType label,
252  typename TImage::IndexValueType i,
253  typename TImage::IndexValueType j,
254  typename SliceType::Pointer& iconn,
255  typename SliceType::Pointer& jconn );
256 
262  void
263  InterpolateAlong( int axis, TImage* out, float startProgress, float endProgress);
264 
266  void
267  Extrapolate( int axis,
268  TImage* out,
269  typename TImage::PixelType label,
270  typename TImage::IndexValueType i,
271  typename TImage::IndexValueType j,
272  typename SliceType::Pointer& iConn,
273  typename TImage::PixelType iRegionId );
274 
276  typename FloatSliceType::Pointer
277  MaurerDM( typename BoolSliceType::Pointer& inImage );
278 
281  std::vector< typename BoolSliceType::Pointer >
282  GenerateDilationSequence( typename BoolSliceType::Pointer& begin,
283  typename BoolSliceType::Pointer& end );
284 
286  typename BoolSliceType::Pointer
287  FindMedianImageDilations( typename BoolSliceType::Pointer& intersection,
288  typename BoolSliceType::Pointer& iMask,
289  typename BoolSliceType::Pointer& jMask );
290 
292  typename BoolSliceType::Pointer
293  FindMedianImageDistances( typename BoolSliceType::Pointer& intersection,
294  typename BoolSliceType::Pointer& iMask,
295  typename BoolSliceType::Pointer& jMask );
296 
298  void
299  Interpolate1to1( int axis,
300  TImage* out,
301  typename TImage::PixelType label,
302  typename TImage::IndexValueType i,
303  typename TImage::IndexValueType j,
304  typename SliceType::Pointer& iConn,
305  typename TImage::PixelType iRegionId,
306  typename SliceType::Pointer& jConn,
307  typename TImage::PixelType jRegionId,
308  const typename SliceType::IndexType& translation,
309  bool recursive );
310 
311  using PixelList = std::vector< typename TImage::PixelType >;
312 
314  void
315  Interpolate1toN( int axis,
316  TImage* out,
317  typename TImage::PixelType label,
318  typename TImage::IndexValueType i,
319  typename TImage::IndexValueType j,
320  typename SliceType::Pointer& iConn,
321  typename TImage::PixelType iRegionId,
322  typename SliceType::Pointer& jConn,
323  const PixelList& jRegionIds,
324  const typename SliceType::IndexType& translation );
325 
327  typename SliceType::Pointer
328  TranslateImage( typename SliceType::Pointer& image,
329  const typename SliceType::IndexType& translation,
330  typename SliceType::RegionType newRegion );
331 
334  IdentifierType
335  CardinalSymmetricDifference( typename BoolSliceType::Pointer& shape1, typename BoolSliceType::Pointer& shape2 );
336 
338  void
339  AllocateOutputs() override;
340 
342  typename SliceType::IndexType
343  Centroid( typename SliceType::Pointer& conn, const PixelList& regionIds );
344 
347  void
348  IntersectionRegions( const typename SliceType::IndexType& translation,
349  typename SliceType::RegionType& iRegion,
350  typename SliceType::RegionType& jRegion );
351 
353  IdentifierType
354  Intersection( typename SliceType::Pointer& iConn,
355  typename TImage::PixelType iRegionId,
356  typename SliceType::Pointer& jConn,
357  const PixelList& jRegionIds,
358  const typename SliceType::IndexType& translation );
359 
361  typename SliceType::IndexType
362  Align( typename SliceType::Pointer& iConn,
363  typename TImage::PixelType iRegionId,
364  typename SliceType::Pointer& jConn,
365  const PixelList& jRegionIds );
366 
367  using BoundingBoxesType = itksys::hash_map< typename TImage::PixelType, typename TImage::RegionType >;
368  BoundingBoxesType m_BoundingBoxes; // bounding box for each label
369 
371  typename SliceType::RegionType
372  BoundingBox( itk::SmartPointer< SliceType > image );
373 
377  template< typename T2 >
378  void
379  ExpandRegion( typename T2::RegionType& region, const typename T2::IndexType& index );
380 
382  typename SliceType::Pointer
383  RegionedConnectedComponents( const typename TImage::RegionType& region,
384  typename TImage::PixelType label,
385  IdentifierType& objectCount );
386 
388  typename BoolSliceType::Pointer
389  Dilate1( typename BoolSliceType::Pointer& seed, typename BoolSliceType::Pointer& mask );
390 
391  using RoiType = ExtractImageFilter< TImage, SliceType >;
392  typename RoiType::Pointer m_RoI;
393 
394  using BinarizerType = BinaryThresholdImageFilter< SliceType, BoolSliceType >;
395  typename BinarizerType::Pointer m_Binarizer;
396 
397  using ConnectedComponentsType = ConnectedComponentImageFilter< BoolSliceType, SliceType >;
398  typename ConnectedComponentsType::Pointer m_ConnectedComponents;
399 };
400 } // namespace itk
401 
402 #ifndef ITK_MANUAL_INSTANTIATION
403 #include "itkMorphologicalContourInterpolator.hxx"
404 #endif
405 
406 #endif // itkMorphologicalContourInterpolator_h
SliceType::Pointer RegionedConnectedComponents(const typename TImage::RegionType &region, typename TImage::PixelType label, IdentifierType &objectCount)
Image< bool, TImage::ImageDimension > BoolImageType
void IntersectionRegions(const typename SliceType::IndexType &translation, typename SliceType::RegionType &iRegion, typename SliceType::RegionType &jRegion)
void InterpolateBetweenTwo(int axis, TImage *out, typename TImage::PixelType label, typename TImage::IndexValueType i, typename TImage::IndexValueType j, typename SliceType::Pointer &iconn, typename SliceType::Pointer &jconn)
Image< float, TImage::ImageDimension - 1 > FloatSliceType
SliceSetType GetLabeledSliceIndices(unsigned int axis, typename TImage::PixelType label)
itkSetMacro(Label, typename TImage::PixelType)
Simplified inverse ITK transforms.
itkTypeMacro(MorphologicalContourInterpolator, ImageToImageFilter)
std::set< typename TImage::IndexValueType > SliceSetType
void SetLabeledSliceIndices(unsigned int axis, typename TImage::PixelType label, const std::vector< typename TImage::IndexValueType > &indices)
void Interpolate1toN(int axis, TImage *out, typename TImage::PixelType label, typename TImage::IndexValueType i, typename TImage::IndexValueType j, typename SliceType::Pointer &iConn, typename TImage::PixelType iRegionId, typename SliceType::Pointer &jConn, const PixelList &jRegionIds, const typename SliceType::IndexType &translation)
std::vector< typename TImage::PixelType > PixelList
itkGetConstMacro(Label, typename TImage::PixelType)
bool ImagesEqual(typename BoolSliceType::Pointer &a, typename BoolSliceType::Pointer &b)
std::vector< typename BoolSliceType::Pointer > GenerateDilationSequence(typename BoolSliceType::Pointer &begin, typename BoolSliceType::Pointer &end)
SliceType::IndexType Centroid(typename SliceType::Pointer &conn, const PixelList &regionIds)
SliceType::Pointer TranslateImage(typename SliceType::Pointer &image, const typename SliceType::IndexType &translation, typename SliceType::RegionType newRegion)
itksys::hash_map< typename TImage::PixelType, typename TImage::RegionType > BoundingBoxesType
BoolSliceType::Pointer FindMedianImageDilations(typename BoolSliceType::Pointer &intersection, typename BoolSliceType::Pointer &iMask, typename BoolSliceType::Pointer &jMask)
~MorphologicalContourInterpolator() override=default
BinaryThresholdImageFilter< SliceType, BoolSliceType > BinarizerType
itksys::hash_map< typename TImage::PixelType, SliceSetType > LabeledSlicesType
Interpolates contours between slices. Based on a paper by Albu et al.
Image< bool, TImage::ImageDimension - 1 > BoolSliceType
BoolSliceType::Pointer Dilate1(typename BoolSliceType::Pointer &seed, typename BoolSliceType::Pointer &mask)
void Extrapolate(int axis, TImage *out, typename TImage::PixelType label, typename TImage::IndexValueType i, typename TImage::IndexValueType j, typename SliceType::Pointer &iConn, typename TImage::PixelType iRegionId)
BoolSliceType::Pointer FindMedianImageDistances(typename BoolSliceType::Pointer &intersection, typename BoolSliceType::Pointer &iMask, typename BoolSliceType::Pointer &jMask)
ConnectedComponentImageFilter< BoolSliceType, SliceType > ConnectedComponentsType
ITK_DISALLOW_COPY_AND_ASSIGN(MorphologicalContourInterpolator)
void ExpandRegion(typename T2::RegionType &region, const typename T2::IndexType &index)
itkGetMacro(Label, typename TImage::PixelType)
void SetLabeledSliceIndices(unsigned int axis, typename TImage::PixelType label, const SliceSetType &indices)
IdentifierType CardinalSymmetricDifference(typename BoolSliceType::Pointer &shape1, typename BoolSliceType::Pointer &shape2)
void Interpolate1to1(int axis, TImage *out, typename TImage::PixelType label, typename TImage::IndexValueType i, typename TImage::IndexValueType j, typename SliceType::Pointer &iConn, typename TImage::PixelType iRegionId, typename SliceType::Pointer &jConn, typename TImage::PixelType jRegionId, const typename SliceType::IndexType &translation, bool recursive)
FloatSliceType::Pointer MaurerDM(typename BoolSliceType::Pointer &inImage)
ExtractImageFilter< TImage, SliceType > RoiType
Image< typename TImage::PixelType, TImage::ImageDimension - 1 > SliceType
SliceType::IndexType Align(typename SliceType::Pointer &iConn, typename TImage::PixelType iRegionId, typename SliceType::Pointer &jConn, const PixelList &jRegionIds)
void InterpolateAlong(int axis, TImage *out, float startProgress, float endProgress)
SliceType::RegionType BoundingBox(itk::SmartPointer< SliceType > image)
IdentifierType Intersection(typename SliceType::Pointer &iConn, typename TImage::PixelType iRegionId, typename SliceType::Pointer &jConn, const PixelList &jRegionIds, const typename SliceType::IndexType &translation)