forked from carma-center/carma_slicer_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarmaAxialDilate.cxx
157 lines (125 loc) · 4.51 KB
/
CarmaAxialDilate.cxx
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
156
157
//std
#include <string>
// auto-generated
#include "CarmaAxialDilateCLP.h"
#include "CarmaAxialDilate.h"
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>
#include <itkSliceBySliceImageFilter.h>
#include "itkPluginUtilities.h"
#include <itkBinaryDilateImagefilter.h>
#include "itkBinaryBallStructuringElement.h"
// Use an anonymous namespace to keep class types and function names
// from colliding when module is used as shared object module. Every
// thing should be in an anonymous namespace except for the module
// entry point, e.g. main()
//
namespace
{
template <class T>
int DoIt( int argc, char * argv[], T )
{
PARSE_ARGS;
typedef T PixelType;
typedef itk::Image< PixelType, 3 > ImageType;
typedef itk::Image< PixelType, 2 > TwoDImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
// read mask
typename ReaderType::Pointer mask_reader = ReaderType::New();
mask_reader->SetFileName(targetFileName);
typename ImageType::Pointer mask_image = mask_reader->GetOutput();
mask_reader->Update();
typedef itk::BinaryBallStructuringElement<
PixelType,2> StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(4);
structuringElement.CreateStructuringElement();
typedef itk::BinaryDilateImageFilter< TwoDImageType, TwoDImageType, StructuringElementType> BinaryDilateImageFilterType;
typedef itk::SliceBySliceImageFilter< ImageType, ImageType > SliceBySliceFilterType;
typename BinaryDilateImageFilterType::Pointer dilate_filter = BinaryDilateImageFilterType::New();
dilate_filter->SetKernel( structuringElement );
dilate_filter->SetDilateValue( 1 );
typename SliceBySliceFilterType::Pointer filter = SliceBySliceFilterType::New();
filter->SetDimension( 2 );
filter->SetFilter( dilate_filter );
filter->SetInput( mask_image );
/*
// 3D dilation
typedef itk::BinaryBallStructuringElement<
ImageType::PixelType,3> StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(2);
structuringElement.CreateStructuringElement();
typedef itk::BinaryDilateImageFilter< ImageType, ImageType, StructuringElementType> BinaryDilateImageFilterType;
BinaryDilateImageFilterType::Pointer dilate_filter = BinaryDilateImageFilterType::New();
dilate_filter->SetDilateValue( 1 );
dilate_filter->SetKernel( structuringElement );
dilate_filter->SetInput( mask_image );
*/
typename WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
//writer->SetInput(dilate_filter->GetOutput());
writer->SetInput(filter->GetOutput());
writer->UseCompressionOn();
writer->Update();
return 0;
}
} // end of anonymous namespace
int main( int argc, char * argv[] )
{
PARSE_ARGS;
itk::ImageIOBase::IOPixelType pixelType;
itk::ImageIOBase::IOComponentType componentType;
try
{
itk::GetImageType(targetFileName, pixelType, componentType);
// This filter handles all types on input, but only produces
// signed types
switch( componentType )
{
case itk::ImageIOBase::UCHAR:
return DoIt( argc, argv, static_cast<unsigned char>(0) );
break;
case itk::ImageIOBase::CHAR:
return DoIt( argc, argv, static_cast<char>(0) );
break;
case itk::ImageIOBase::USHORT:
return DoIt( argc, argv, static_cast<unsigned short>(0) );
break;
case itk::ImageIOBase::SHORT:
return DoIt( argc, argv, static_cast<short>(0) );
break;
case itk::ImageIOBase::UINT:
return DoIt( argc, argv, static_cast<unsigned int>(0) );
break;
case itk::ImageIOBase::INT:
return DoIt( argc, argv, static_cast<int>(0) );
break;
case itk::ImageIOBase::ULONG:
return DoIt( argc, argv, static_cast<unsigned long>(0) );
break;
case itk::ImageIOBase::LONG:
return DoIt( argc, argv, static_cast<long>(0) );
break;
case itk::ImageIOBase::FLOAT:
return DoIt( argc, argv, static_cast<float>(0) );
break;
case itk::ImageIOBase::DOUBLE:
return DoIt( argc, argv, static_cast<double>(0) );
break;
case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE:
default:
std::cout << "unknown component type" << std::endl;
break;
}
}
catch( itk::ExceptionObject & excep )
{
std::cerr << argv[0] << ": exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}