Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
Step6RegionGrowing.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #include "Step6.h"
17 
18 #include <mitkPointSet.h>
19 #include <mitkProperties.h>
20 
21 #include <itkConnectedThresholdImageFilter.h>
22 #include <itkCurvatureFlowImageFilter.h>
23 
24 #include <mitkImageAccessByItk.h>
25 #include <mitkImageCast.h>
26 #include <mitkLevelWindowProperty.h>
27 
28 template <typename TPixel, unsigned int VImageDimension>
29 void RegionGrowing(itk::Image<TPixel, VImageDimension> *itkImage, Step6 *step6)
30 {
31  typedef itk::Image<TPixel, VImageDimension> ImageType;
32 
33  typedef float InternalPixelType;
34  typedef itk::Image<InternalPixelType, VImageDimension> InternalImageType;
35 
36  mitk::BaseGeometry *geometry = step6->m_FirstImage->GetGeometry();
37 
38  // create itk::CurvatureFlowImageFilter for smoothing and set itkImage as input
39  typedef itk::CurvatureFlowImageFilter<ImageType, InternalImageType> CurvatureFlowFilter;
40  typename CurvatureFlowFilter::Pointer smoothingFilter = CurvatureFlowFilter::New();
41 
42  smoothingFilter->SetInput(itkImage);
43  smoothingFilter->SetNumberOfIterations(4);
44  smoothingFilter->SetTimeStep(0.0625);
45 
46  // create itk::ConnectedThresholdImageFilter and set filtered image as input
47  typedef itk::ConnectedThresholdImageFilter<InternalImageType, ImageType> RegionGrowingFilterType;
48  typedef typename RegionGrowingFilterType::IndexType IndexType;
49  typename RegionGrowingFilterType::Pointer regGrowFilter = RegionGrowingFilterType::New();
50 
51  regGrowFilter->SetInput(smoothingFilter->GetOutput());
52  regGrowFilter->SetLower(step6->GetThresholdMin());
53  regGrowFilter->SetUpper(step6->GetThresholdMax());
54 
55  // convert the points in the PointSet m_Seeds (in world-coordinates) to
56  // "index" values, i.e. points in pixel coordinates, and add these as seeds
57  // to the RegionGrower
58  mitk::PointSet::PointsConstIterator pit, pend = step6->m_Seeds->GetPointSet()->GetPoints()->End();
59  IndexType seedIndex;
60  for (pit = step6->m_Seeds->GetPointSet()->GetPoints()->Begin(); pit != pend; ++pit)
61  {
62  geometry->WorldToIndex(pit.Value(), seedIndex);
63  regGrowFilter->AddSeed(seedIndex);
64  }
65 
66  regGrowFilter->GetOutput()->Update();
67  mitk::Image::Pointer mitkImage = mitk::Image::New();
68  mitk::CastToMitkImage(regGrowFilter->GetOutput(), mitkImage);
69 
70  if (step6->m_ResultNode.IsNull())
71  {
72  step6->m_ResultNode = mitk::DataNode::New();
73  step6->m_DataStorage->Add(step6->m_ResultNode);
74  }
75  step6->m_ResultNode->SetData(mitkImage);
76  // set some additional properties
77  step6->m_ResultNode->SetProperty("name", mitk::StringProperty::New("segmentation"));
78  step6->m_ResultNode->SetProperty("binary", mitk::BoolProperty::New(true));
79  step6->m_ResultNode->SetProperty("color", mitk::ColorProperty::New(1.0, 0.0, 0.0));
80  step6->m_ResultNode->SetProperty("volumerendering", mitk::BoolProperty::New(true));
81  step6->m_ResultNode->SetProperty("layer", mitk::IntProperty::New(1));
82  mitk::LevelWindowProperty::Pointer levWinProp = mitk::LevelWindowProperty::New();
83  mitk::LevelWindow levelwindow;
84  levelwindow.SetAuto(mitkImage);
85  levWinProp->SetLevelWindow(levelwindow);
86  step6->m_ResultNode->SetProperty("levelwindow", levWinProp);
87 
88  step6->m_ResultImage = static_cast<mitk::Image *>(step6->m_ResultNode->GetData());
89 }
90 
91 /**
92 \example Step6RegionGrowing.txx
93 */