Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkMaskAndCutRoiImageFilter.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
13 
15 #include "mitkImageCast.h"
16 
18 {
19  this->SetNumberOfRequiredInputs(2);
21  m_RoiFilter = ROIFilterType::New();
23 }
24 
26 {
27 }
28 
30 {
31  mitk::Image::Pointer image = dynamic_cast<mitk::Image *>(roi);
32 
33  if (image.IsNotNull())
34  {
35  this->SetInput(1, image);
36  return;
37  }
38 
39  mitk::BoundingObject::Pointer boundingObject = dynamic_cast<mitk::BoundingObject *>(roi);
40  if (boundingObject.IsNotNull() && this->GetInput(0) != nullptr)
41  {
43  filter->SetBoundingObject(boundingObject);
44  filter->SetInput(this->GetInput(0));
45  filter->Update();
46 
47  this->SetInput(1, filter->GetOutput());
48  return;
49  }
50 }
51 
53 {
54  return m_outputImage;
55 }
56 
58 {
59  mitk::Image::ConstPointer inputImage = this->GetInput(0);
60  mitk::Image::ConstPointer maskImage = this->GetInput(1);
61  // mitk::Image::Pointer outputImage = this->GetOutput();
62  // temporary fix for bug #
63  m_outputImage = this->GetOutput();
64 
65  ItkImageType::Pointer itkImage = ItkImageType::New();
67 
68  m_CropFilter->SetInput(maskImage);
69  m_CropFilter->SetBackgroundValue(0);
70  m_CropFilter->Update();
71 
72  RegionType region = m_CropFilter->GetCroppingRegion();
73 
74  mitk::CastToItkImage(inputImage, itkImage);
75  m_RoiFilter->SetInput(itkImage);
76  m_RoiFilter->SetRegionOfInterest(region);
77  m_RoiFilter->Update();
78 
79  mitk::CastToMitkImage(m_RoiFilter->GetOutput(), tmpImage);
80 
81  m_MaskFilter->SetInput(0, tmpImage);
82  m_MaskFilter->SetMask(m_CropFilter->GetOutput());
83 
84  m_MaskFilter->SetOutsideValue(-32765);
85  m_MaskFilter->Update();
86  m_MaxValue = m_MaskFilter->GetMaxValue();
87  m_MinValue = m_MaskFilter->GetMinValue();
88 
89  // temporary fix for bug #
90  m_outputImage = m_MaskFilter->GetOutput();
91  m_outputImage->DisconnectPipeline();
92 }
mitk::AutoCropImageFilter::Pointer m_CropFilter
Base of all data objects.
Definition: mitkBaseData.h:37
virtual void SetInput(const InputImageType *image)
static Pointer New()
superclass of all bounding objects (cylinder, cuboid,...)
static Pointer New()
mitk::MaskImageFilter::Pointer m_MaskFilter
Image class for storing images.
Definition: mitkImage.h:72
mitk::Image::Pointer image
static Pointer New()
InputImageType * GetInput(void)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
Definition: mitkImageCast.h:74
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.