-
Notifications
You must be signed in to change notification settings - Fork 2
/
DilationBinary.cpp
53 lines (47 loc) · 2.17 KB
/
DilationBinary.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
//Dilation on binary image
void MainWindow::OnShowDilationBinaryClicked()
{
unsigned int radius=2;
ui->radiusSlider->setMinimum(0);
ui->radiusSlider->setMaximum(50);
radius = ui->radiusSlider->value();
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
typedef itk::Image< InputPixelType, 2 > InputImageType;
typedef itk::Image< OutputPixelType, 2 > OutputImageType;
typedef itk::Image<unsigned char, 2> ImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName((const char*)filename.toStdString().c_str());
typedef itk::BinaryBallStructuringElement<
ImageType::PixelType,2> StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(radius);
structuringElement.CreateStructuringElement();
typedef itk::BinaryDilateImageFilter <ImageType, ImageType, StructuringElementType>
BinaryDilateImageFilterType;
BinaryDilateImageFilterType::Pointer dilateFilter
= BinaryDilateImageFilterType::New();
dilateFilter->SetInput(reader->GetOutput());
dilateFilter->SetKernel(structuringElement);
ConnectorType::Pointer connector = ConnectorType::New();
connector->SetInput(dilateFilter->GetOutput());
vtkSmartPointer<vtkImageActor> actor =
vtkSmartPointer<vtkImageActor>::New();
#if VTK_MAJOR_VERSION <= 5
actor->SetInput(connector->GetOutput());
#else
connector->Update();
actor->GetMapper()->SetInputData(connector->GetOutput());
#endif
vtkSmartPointer<vtkRenderer> dilateErodeRenderer =
vtkSmartPointer<vtkRenderer>::New();
dilateErodeRenderer->AddActor(actor);
dilateErodeRenderer->ResetCamera();
ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(dilateErodeRenderer);
//ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(originalRenderer);
ui->qvtkWidget_4->GetRenderWindow()->Render();
}