1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
18 #include <mitkPointSet.h>
19 #include <mitkProperties.h>
21 #include <itkConnectedThresholdImageFilter.h>
22 #include <itkCurvatureFlowImageFilter.h>
24 #include <mitkImageAccessByItk.h>
25 #include <mitkImageCast.h>
26 #include <mitkLevelWindowProperty.h>
28 template <typename TPixel, unsigned int VImageDimension>
29 void RegionGrowing(itk::Image<TPixel, VImageDimension> *itkImage, Step6 *step6)
31 typedef itk::Image<TPixel, VImageDimension> ImageType;
33 typedef float InternalPixelType;
34 typedef itk::Image<InternalPixelType, VImageDimension> InternalImageType;
36 mitk::BaseGeometry *geometry = step6->m_FirstImage->GetGeometry();
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();
42 smoothingFilter->SetInput(itkImage);
43 smoothingFilter->SetNumberOfIterations(4);
44 smoothingFilter->SetTimeStep(0.0625);
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();
51 regGrowFilter->SetInput(smoothingFilter->GetOutput());
52 regGrowFilter->SetLower(step6->GetThresholdMin());
53 regGrowFilter->SetUpper(step6->GetThresholdMax());
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();
60 for (pit = step6->m_Seeds->GetPointSet()->GetPoints()->Begin(); pit != pend; ++pit)
62 geometry->WorldToIndex(pit.Value(), seedIndex);
63 regGrowFilter->AddSeed(seedIndex);
66 regGrowFilter->GetOutput()->Update();
67 mitk::Image::Pointer mitkImage = mitk::Image::New();
68 mitk::CastToMitkImage(regGrowFilter->GetOutput(), mitkImage);
70 if (step6->m_ResultNode.IsNull())
72 step6->m_ResultNode = mitk::DataNode::New();
73 step6->m_DataStorage->Add(step6->m_ResultNode);
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);
88 step6->m_ResultImage = static_cast<mitk::Image *>(step6->m_ResultNode->GetData());
92 \example Step6RegionGrowing.txx