-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpeningGrayscale.cpp
56 lines (48 loc) · 2.25 KB
/
OpeningGrayscale.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
56
#include "mainwindow.h"
#include "ui_mainwindow.h"
//Opening in grayscale
void MainWindow::OnShowOpeningGrayscaleClicked()
{
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::GrayscaleConnectedOpeningImageFilter <ImageType, ImageType>
GrayscaleConnectedOpeningImageFilterType;
GrayscaleConnectedOpeningImageFilterType::Pointer openingFilter
= GrayscaleConnectedOpeningImageFilterType::New();
//openingFilter->SetKernel(structuringElement);
openingFilter->SetInput(reader->GetOutput());
openingFilter->Update();
ConnectorType::Pointer connector = ConnectorType::New();
connector->SetInput(openingFilter->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> openingRenderer =
vtkSmartPointer<vtkRenderer>::New();
openingRenderer->AddActor(actor);
openingRenderer->ResetCamera();
ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(openingRenderer);
//ui->qvtkWidget_4->GetRenderWindow()->AddRenderer(originalRenderer);
ui->qvtkWidget_4->GetRenderWindow()->Render();
}