Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkCollectionGrayOpening.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 ===================================================================*/
16 
18 #include <mitkITKImageImport.h>
19 #include <mitkImageCast.h>
20 
21 #include "itkBinaryBallStructuringElement.h"
22 #include "itkBinaryDilateImageFilter.h"
23 #include "itkFlatStructuringElement.h"
24 #include "itkGrayscaleMorphologicalOpeningImageFilter.h"
25 
27  std::string name,
28  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 << "PerformGrayOpening - 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 itkImage = BinaryImage::New();
48  Image::Pointer tmp = dataTimeStep->GetMitkImage(name).GetPointer();
49  if (tmp.IsNull())
50  MITK_ERROR << "null";
51  CastToItkImage(tmp, itkImage);
52  if (itkImage.IsNull())
53  MITK_ERROR << "Image " << name << " does not exist. Fatal.";
54 
55  typedef itk::FlatStructuringElement<3> StructuringElementType;
56  StructuringElementType::RadiusType elementRadius;
57  elementRadius.Fill(1);
58  elementRadius[2] = 0;
59  StructuringElementType structuringElement = StructuringElementType::Box(elementRadius);
60 
61  typedef itk::GrayscaleMorphologicalOpeningImageFilter<ImageType, ImageType, StructuringElementType>
62  DilateImageFilterType;
63 
65  dilateFilter0->SetInput(itkImage);
66  dilateFilter0->SetKernel(structuringElement);
67  dilateFilter0->Update();
68 
70  dilateFilter1->SetInput(dilateFilter0->GetOutput());
71  dilateFilter1->SetKernel(structuringElement);
72  dilateFilter1->Update();
73 
74  Image::Pointer dil = GrabItkImageMemory(dilateFilter1->GetOutput());
75  dataTimeStep->AddData(dil.GetPointer(), name + suffix, "");
76  }
77  }
78 }
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.
static void PerformGrayOpening(mitk::DataCollection *dataCollection, std::string name, std::string suffix)
PerformGrayOpening - Opening operation on a specific modality type wihtin the DataCollection. Creates a new item.
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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.