File: vtkvmtkGrayscaleMorphologyImageFilter.cxx

package info (click to toggle)
vmtk 1.3%2Bdfsg-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 8,932 kB
  • sloc: cpp: 82,947; ansic: 31,817; python: 21,462; perl: 381; makefile: 93; ruby: 41; sh: 19
file content (155 lines) | stat: -rw-r--r-- 4,956 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*=========================================================================

Program:   VMTK
Module:    $RCSfile: vtkvmtkGrayscaleMorphologyImageFilter.cxx,v $
Language:  C++
Date:      $Date: 2006/04/06 16:48:25 $
Version:   $Revision: 1.1 $

  Copyright (c) Luca Antiga, David Steinman. All rights reserved.
  See LICENCE file for details.

  Portions of this code are covered under the VTK copyright.
  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm 
  for details.

  Portions of this code are covered under the ITK copyright.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm
  for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "vtkvmtkGrayscaleMorphologyImageFilter.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"

#include "vtkvmtkITKFilterUtilities.h"

#include "itkBinaryBallStructuringElement.h"
#include "itkGrayscaleMorphologicalClosingImageFilter.h"
#include "itkGrayscaleMorphologicalOpeningImageFilter.h"
#include "itkGrayscaleDilateImageFilter.h"
#include "itkGrayscaleErodeImageFilter.h"


vtkStandardNewMacro(vtkvmtkGrayscaleMorphologyImageFilter);

vtkvmtkGrayscaleMorphologyImageFilter::vtkvmtkGrayscaleMorphologyImageFilter()
{
  this->BallRadius[0] = this->BallRadius[1] = this->BallRadius[2] = 1;
  this->Operation = ERODE;
}

vtkvmtkGrayscaleMorphologyImageFilter::~vtkvmtkGrayscaleMorphologyImageFilter()
{
}

int vtkvmtkGrayscaleMorphologyImageFilter::RequestInformation (
  vtkInformation * vtkNotUsed(request),
  vtkInformationVector **inputVector,
  vtkInformationVector *outputVector)
{
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
  vtkDataObject::SetPointDataActiveScalarInfo(outInfo, VTK_FLOAT, -1);

  return 1;
}

void vtkvmtkGrayscaleMorphologyImageFilter::SimpleExecute(vtkImageData *input, vtkImageData *output)
{
  typedef float PixelType;
  const int Dimension = 3;
  typedef itk::Image<PixelType, Dimension> ImageType;

  ImageType::Pointer inImage = ImageType::New();

  vtkvmtkITKFilterUtilities::VTKToITKImage<ImageType>(input,inImage);

  typedef itk::BinaryBallStructuringElement<PixelType, Dimension> KernelType;
  typedef itk::GrayscaleMorphologicalClosingImageFilter<ImageType, ImageType, KernelType> ClosingFilterType;
  typedef itk::GrayscaleMorphologicalOpeningImageFilter<ImageType, ImageType, KernelType> OpeningFilterType;
  typedef itk::GrayscaleErodeImageFilter<ImageType, ImageType, KernelType> ErodeFilterType;
  typedef itk::GrayscaleDilateImageFilter<ImageType, ImageType, KernelType> DilateFilterType;

  KernelType ball;
  KernelType::SizeType ballRadius;
  ballRadius[0] = this->BallRadius[0];
  ballRadius[1] = this->BallRadius[1];
  ballRadius[2] = this->BallRadius[2];
  ball.SetRadius(ballRadius);
  ball.CreateStructuringElement();

  ImageType::Pointer outputImage;

  if (this->Operation == CLOSE)
    {
    ClosingFilterType::Pointer imageFilter = ClosingFilterType::New();
    imageFilter->SetKernel(ball);
    imageFilter->SetInput(inImage);
    imageFilter->SafeBorderOff();
    try {
      imageFilter->Update();
    }
    catch( itk::ExceptionObject & excep )
    {
      std::cerr << "Exception catched !" << std::endl;
      std::cerr << excep << std::endl;
    }
    outputImage = imageFilter->GetOutput();
    }
  if (this->Operation == OPEN)
    {
    OpeningFilterType::Pointer imageFilter = OpeningFilterType::New();
    imageFilter->SetKernel(ball);
    imageFilter->SetInput(inImage);
    imageFilter->SafeBorderOff();
    try {
      imageFilter->Update();
    }
    catch( itk::ExceptionObject & excep )
    {
      std::cerr << "Exception catched !" << std::endl;
      std::cerr << excep << std::endl;
    }
    outputImage = imageFilter->GetOutput();
    }
  if (this->Operation == DILATE)
    {
    DilateFilterType::Pointer imageFilter = DilateFilterType::New();
    imageFilter->SetKernel(ball);
    imageFilter->SetInput(inImage);
    try {
      imageFilter->Update();
    }
    catch( itk::ExceptionObject & excep )
    {
      std::cerr << "Exception catched !" << std::endl;
      std::cerr << excep << std::endl;
    }
    outputImage = imageFilter->GetOutput();
    }
  if (this->Operation == ERODE)
    {
    ErodeFilterType::Pointer imageFilter = ErodeFilterType::New();
    imageFilter->SetKernel(ball);
    imageFilter->SetInput(inImage);
    try {
      imageFilter->Update();
    }
    catch( itk::ExceptionObject & excep )
    {
      std::cerr << "Exception catched !" << std::endl;
      std::cerr << excep << std::endl;
    }
    outputImage = imageFilter->GetOutput();
    }

  vtkvmtkITKFilterUtilities::ITKToVTKImage<ImageType>(outputImage,output);
}