-
Notifications
You must be signed in to change notification settings - Fork 2
/
ClosingGrayscale.cpp
55 lines (48 loc) · 2.25 KB
/
ClosingGrayscale.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
54
55
#include "mainwindow.h"
#include "ui_mainwindow.h"
//Closing on grayscale
void MainWindow::OnShowClosingGrayscaleClicked()
{
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());
unsigned int radius=2;
ui->radiusSlider->setMinimum(0);
ui->radiusSlider->setMaximum(50);
radius = ui->radiusSlider->value();
typedef itk::BinaryBallStructuringElement<ImageType::PixelType, 2>
StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(radius);
structuringElement.CreateStructuringElement();
typedef itk::GrayscaleConnectedClosingImageFilter <ImageType, ImageType>
GrayscaleConnectedClosingImageFilterType;
GrayscaleConnectedClosingImageFilterType::Pointer closingFilter
= GrayscaleConnectedClosingImageFilterType::New();
//closingFilter->SetKernel(structuringElement);
closingFilter->SetInput(reader->GetOutput());
closingFilter->Update();
ConnectorType::Pointer connector = ConnectorType::New();
connector->SetInput(closingFilter->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> closingRenderer =
vtkSmartPointer<vtkRenderer>::New();
closingRenderer->AddActor(actor);
closingRenderer->ResetCamera();
ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(closingRenderer);
//ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(originalRenderer);
ui->qvtkWidget_4->GetRenderWindow()->Render();
}