Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCollectionDilatation.cpp
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 ===================================================================*/
17 
18 #include <mitkITKImageImport.h>
19 #include <mitkImageCast.h>
20 
21 #include "itkBinaryBallStructuringElement.h"
22 #include "itkBinaryDilateImageFilter.h"
23 #include "itkBinaryErodeImageFilter.h"
24 #include "itkFlatStructuringElement.h"
25 #include "itkGrayscaleDilateImageFilter.h"
26 
28  mitk::DataCollection *dataCollection, std::string name, unsigned int xy, unsigned int z, std::string suffix)
29 {
30  for (size_t patient = 0; patient < dataCollection->Size(); ++patient)
31  {
32  DataCollection *dataPatient = dynamic_cast<DataCollection *>(dataCollection->GetData(patient).GetPointer());
33  if (dataPatient == NULL)
34  MITK_ERROR << "DilateBinaryByName - Structure of DataCollection is invalid at patient level. Data inconsistent!";
35 
36  if (dataPatient->Size() == 0)
37  MITK_ERROR << "Empty Patient Collective. Probably Fatal.";
38 
39  for (size_t timeStep = 0; timeStep < dataPatient->Size(); ++timeStep)
40  {
41  DataCollection *dataTimeStep = dynamic_cast<DataCollection *>(dataPatient->GetData(timeStep).GetPointer());
42  if (dataTimeStep == NULL)
44  << "DilateBinaryByName- Structure of DataCollection is invalid at time step level. Data inconsistent!";
45 
46  BinaryImage::Pointer itkTumorSeed = BinaryImage::New();
47  Image *tumorSeed = dynamic_cast<Image *>(dataTimeStep->GetMitkImage(name).GetPointer());
48  if (tumorSeed == NULL)
49  MITK_ERROR << "Image " << name << " does not exits. Fatal.";
50 
51  CastToItkImage(tumorSeed, itkTumorSeed);
52 
53  typedef itk::FlatStructuringElement<3> StructuringElementType;
54  StructuringElementType::RadiusType elementRadius;
55  elementRadius.Fill(xy);
56  elementRadius[2] = z;
57 
58  StructuringElementType structuringElement = StructuringElementType::Box(elementRadius);
59  typedef itk::BinaryDilateImageFilter<BinaryImage, BinaryImage, StructuringElementType>
60  BinaryDilateImageFilterType;
61 
63  dilateFilter0->SetInput(itkTumorSeed);
64  dilateFilter0->SetKernel(structuringElement);
65  dilateFilter0->SetForegroundValue(1);
66  dilateFilter0->Update();
67 
68  Image::Pointer dil = GrabItkImageMemory(dilateFilter0->GetOutput());
69 
70  dil->SetGeometry(tumorSeed->GetGeometry());
71  dataTimeStep->AddData(dil.GetPointer(), name + suffix, "Dilated Binary");
72  }
73  }
74 }
75 
77  mitk::DataCollection *dataCollection, std::string name, unsigned int xy, unsigned int z, std::string suffix)
78 {
79  for (size_t patient = 0; patient < dataCollection->Size(); ++patient)
80  {
81  DataCollection *dataPatient = dynamic_cast<DataCollection *>(dataCollection->GetData(patient).GetPointer());
82  if (dataPatient == NULL)
83  MITK_ERROR << "DilateBinaryByName - Structure of DataCollection is invalid at patient level. Data inconsistent!";
84 
85  if (dataPatient->Size() == 0)
86  MITK_ERROR << "Empty Patient Collective. Probably Fatal.";
87 
88  for (size_t timeStep = 0; timeStep < dataPatient->Size(); ++timeStep)
89  {
90  DataCollection *dataTimeStep = dynamic_cast<DataCollection *>(dataPatient->GetData(timeStep).GetPointer());
91  if (dataTimeStep == NULL)
93  << "DilateBinaryByName- Structure of DataCollection is invalid at time step level. Data inconsistent!";
94 
95  BinaryImage::Pointer itkTumorSeed = BinaryImage::New();
96  Image *tumorSeed = dynamic_cast<Image *>(dataTimeStep->GetMitkImage(name).GetPointer());
97  if (tumorSeed == NULL)
98  MITK_ERROR << "Image " << name << " does not exits. Fatal.";
99 
100  CastToItkImage(tumorSeed, itkTumorSeed);
101 
102  typedef itk::FlatStructuringElement<3> StructuringElementType;
103  StructuringElementType::RadiusType elementRadius;
104  elementRadius.Fill(xy);
105  elementRadius[2] = z;
106 
107  StructuringElementType structuringElement = StructuringElementType::Box(elementRadius);
108 
109  typedef itk::BinaryErodeImageFilter<BinaryImage, BinaryImage, StructuringElementType> BinaryErodeImageFilterType;
110 
112  dilateFilter0->SetInput(itkTumorSeed);
113  dilateFilter0->SetKernel(structuringElement);
114  dilateFilter0->SetForegroundValue(1);
115  dilateFilter0->Update();
116 
117  Image::Pointer dil = GrabItkImageMemory(dilateFilter0->GetOutput());
118 
119  dil->SetGeometry(tumorSeed->GetGeometry());
120  dataTimeStep->AddData(dil.GetPointer(), name + suffix, "Dilated Binary");
121  }
122  }
123 }
static void ErodeBinaryByName(DataCollection *dataCollection, std::string name, unsigned int xy=5, unsigned int z=0, std::string suffix="ERODE")
ErodeBinaryByName - Erode all occurances of a modality within a mitk::DataCollection.
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
vcl_size_t Size() const
Size - number of data items in collection.
vcl_size_t AddData(DataObject::Pointer data, std::string name, std::string filePath="")
AddData Add a data item.
mitk::Image::Pointer GetMitkImage(vcl_size_t index)
GetMitkImage - casts data to mitk::Image and returns it.
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
Image class for storing images.
Definition: mitkImage.h:76
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
itk::DataObject::Pointer GetData(vcl_size_t index)
GetData Get original data by index.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:129
static void DilateBinaryByName(DataCollection *dataCollection, std::string name, unsigned int xy=5, unsigned int z=0, std::string suffix="DILATE")
DilateBinaryByName - Dilate all occurances of a modality within a mitk::DataCollection.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.