VMTK
Loading...
Searching...
No Matches
vtkvmtkGrayscaleMorphologyImageFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkGrayscaleMorphologyImageFilter.cxx,v $
5Language: C++
6Date: $Date: 2006/04/06 16:48:25 $
7Version: $Revision: 1.1 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 Portions of this code are covered under the ITK copyright.
17 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
18 for details.
19
20 This software is distributed WITHOUT ANY WARRANTY; without even
21 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22 PURPOSE. See the above copyright notices for more information.
23
24=========================================================================*/
25
27#include "vtkImageData.h"
28#include "vtkInformation.h"
29#include "vtkInformationVector.h"
30#include "vtkObjectFactory.h"
31
33
34#include "itkBinaryBallStructuringElement.h"
35#include "itkGrayscaleMorphologicalClosingImageFilter.h"
36#include "itkGrayscaleMorphologicalOpeningImageFilter.h"
37#include "itkGrayscaleDilateImageFilter.h"
38#include "itkGrayscaleErodeImageFilter.h"
39
40
42
48
52
54 vtkInformation * vtkNotUsed(request),
55 vtkInformationVector **inputVector,
56 vtkInformationVector *outputVector)
57{
58 vtkInformation *outInfo = outputVector->GetInformationObject(0);
59 vtkDataObject::SetPointDataActiveScalarInfo(outInfo, VTK_FLOAT, -1);
60
61 return 1;
62}
63
64void vtkvmtkGrayscaleMorphologyImageFilter::SimpleExecute(vtkImageData *input, vtkImageData *output)
65{
66 typedef float PixelType;
67 const int Dimension = 3;
68 typedef itk::Image<PixelType, Dimension> ImageType;
69
70 ImageType::Pointer inImage = ImageType::New();
71
73
74 typedef itk::BinaryBallStructuringElement<PixelType, Dimension> KernelType;
75 typedef itk::GrayscaleMorphologicalClosingImageFilter<ImageType, ImageType, KernelType> ClosingFilterType;
76 typedef itk::GrayscaleMorphologicalOpeningImageFilter<ImageType, ImageType, KernelType> OpeningFilterType;
77 typedef itk::GrayscaleErodeImageFilter<ImageType, ImageType, KernelType> ErodeFilterType;
78 typedef itk::GrayscaleDilateImageFilter<ImageType, ImageType, KernelType> DilateFilterType;
79
80 KernelType ball;
81 KernelType::SizeType ballRadius;
82 ballRadius[0] = this->BallRadius[0];
83 ballRadius[1] = this->BallRadius[1];
84 ballRadius[2] = this->BallRadius[2];
85 ball.SetRadius(ballRadius);
86 ball.CreateStructuringElement();
87
88 ImageType::Pointer outputImage;
89
90 if (this->Operation == CLOSE)
91 {
92 ClosingFilterType::Pointer imageFilter = ClosingFilterType::New();
93 imageFilter->SetKernel(ball);
94 imageFilter->SetInput(inImage);
95 imageFilter->SafeBorderOff();
96 try {
97 imageFilter->Update();
98 }
99 catch( itk::ExceptionObject & excep )
100 {
101 std::cerr << "Exception caught !" << std::endl;
102 std::cerr << excep << std::endl;
103 }
104 outputImage = imageFilter->GetOutput();
105 }
106 if (this->Operation == OPEN)
107 {
108 OpeningFilterType::Pointer imageFilter = OpeningFilterType::New();
109 imageFilter->SetKernel(ball);
110 imageFilter->SetInput(inImage);
111 imageFilter->SafeBorderOff();
112 try {
113 imageFilter->Update();
114 }
115 catch( itk::ExceptionObject & excep )
116 {
117 std::cerr << "Exception caught !" << std::endl;
118 std::cerr << excep << std::endl;
119 }
120 outputImage = imageFilter->GetOutput();
121 }
122 if (this->Operation == DILATE)
123 {
124 DilateFilterType::Pointer imageFilter = DilateFilterType::New();
125 imageFilter->SetKernel(ball);
126 imageFilter->SetInput(inImage);
127 try {
128 imageFilter->Update();
129 }
130 catch( itk::ExceptionObject & excep )
131 {
132 std::cerr << "Exception caught !" << std::endl;
133 std::cerr << excep << std::endl;
134 }
135 outputImage = imageFilter->GetOutput();
136 }
137 if (this->Operation == ERODE)
138 {
139 ErodeFilterType::Pointer imageFilter = ErodeFilterType::New();
140 imageFilter->SetKernel(ball);
141 imageFilter->SetInput(inImage);
142 try {
143 imageFilter->Update();
144 }
145 catch( itk::ExceptionObject & excep )
146 {
147 std::cerr << "Exception caught !" << std::endl;
148 std::cerr << excep << std::endl;
149 }
150 outputImage = imageFilter->GetOutput();
151 }
152
154}
155
Wraps itk::GrayscaleMorphologyImageFilter.
virtual int RequestInformation(vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *outputVector) override
virtual void SimpleExecute(vtkImageData *input, vtkImageData *output) override
static void ITKToVTKImage(typename TImage::Pointer input, vtkImageData *output)
static void VTKToITKImage(vtkImageData *input, typename TImage::Pointer output)
vtkStandardNewMacro(vtkvmtkGrayscaleMorphologyImageFilter)