-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShikataLineFiltering.cxx
More file actions
362 lines (285 loc) · 12.6 KB
/
ShikataLineFiltering.cxx
File metadata and controls
362 lines (285 loc) · 12.6 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*=========================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkHessianToShikataMeasureImageFilter.h"
#include "itkShikataMultiScaleHessianBasedMeasureImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkSignedDanielssonDistanceMapImageFilter.h"
#include "itkShiftScaleInPlaceImageFilter.h"
#include "antsCommandLineParser.h"
int itkMultiScaleHessianBasedMeasureImageFilterTest(int argc, char *argv[]);
int main(int argc, char *argv[]) {
// itk::MultiThreader::SetGlobalMaximumNumberOfThreads( 1 );
return itkMultiScaleHessianBasedMeasureImageFilterTest(argc, argv);
}
template<class ParserPointerType>
void InitializeOption(ParserPointerType &parser) {
typedef typename ParserPointerType::ObjectType ParserType;
typedef typename ParserType::OptionType OptionType;
{
typename OptionType::Pointer option = OptionType::New();
option->SetLongName(std::string("sigma-list"));
option->SetDescription(
std::string(
"sigma list for multi-scale line filtering, eg. 1x1.414x2.x2.828"));
option->AddValue(std::string("1x1.414x2x2.828x4"));
parser->AddOption(option);
}
{
typename OptionType::Pointer option = OptionType::New();
option->SetLongName(std::string("distance-threshold-list"));
option->SetDescription(
std::string(
"distance threshold list for multi-scale line filtering, coupled with sigma-list"
"eg. 1x1x2x2"));
option->AddValue(std::string("0x1x1x2x2.828"));
parser->AddOption(option);
}
{
typename OptionType::Pointer option = OptionType::New();
option->SetLongName(std::string("distance-map-image"));
option->SetDescription(
std::string(
"output file name of distance map image of input mask "));
option->AddValue(std::string(""));
parser->AddOption(option);
}
{
typename OptionType::Pointer option = OptionType::New();
option->SetLongName(std::string("hessian-image"));
option->SetDescription(
std::string("output file name of hessian map image,"
"for debug use, each pixel is the hessian from "
"the selected scale"));
option->AddValue(std::string(""));
parser->AddOption(option);
}
{
typename OptionType::Pointer option = OptionType::New();
option->SetLongName(std::string("scale-image"));
option->SetDescription(std::string("output file name of scale image,"
"each pixel is the select scale from "
"sigma-list"));
option->AddValue(std::string(""));
parser->AddOption(option);
}
}
template<class TVec, class TStream>
void PrintVector(TVec &v, TStream &s){
unsigned int n = v.size();
if (n==0) return;
s << v[0];
for(unsigned int i=1; i<n;i++)
s << "x" << v[i];
s << std::endl;
}
int itkMultiScaleHessianBasedMeasureImageFilterTest(int argc, char *argv[]) {
typedef itk::ants::CommandLineParser ParserType;
ParserType::Pointer parser = ParserType::New();
InitializeOption(parser);
if (argc < 3) {
std::cerr << "Missing Parameters: " << argv[0]
<< "InputScalarImage InputMaskImage LineFilteringOutputImage"
<< std::endl;
parser->PrintMenu(std::cerr, 5, false);
// << "[--sigma-list AxBxC]"
// << "[--distance-threshold-list DxExF]"
// << "[--distance-map-image DistanceMapImage]"
// << "[--hessian-image HessianImageFileName]"
// << "[--scale-image ScaleImageFileName]" << std::endl;
//
// << " EnhancedOutputImage ScalesOutputImage "
// << " [SigmaMin SigmaMax NumberOfScales ObjectDimension Bright/Dark HessianImage]"
// << std::endl;
return EXIT_FAILURE;
}
//const double SQRT2 = vnl_math::sqrt2; //sqrt(2.0);
std::vector<double> sigmaList;
// sigmaList.resize(5);
// sigmaList[0] = 1;
// sigmaList[1] = SQRT2;
// sigmaList[2] = 2;
// sigmaList[3] = 2 * SQRT2;
// sigmaList[4] = 4;
std::vector<double> distanceThresholdList;
// distanceThresholdList.resize(5);
// distanceThresholdList[0] = 0;
// distanceThresholdList[1] = 1;
// distanceThresholdList[2] = 1;
// distanceThresholdList[3] = 2;
// distanceThresholdList[4] = 2 * SQRT2;
// std::vector<double> sigmaList;
// sigmaList.resize(1);
// sigmaList[0] = 2*SQRT2;
//
// std::vector<double> distanceThresholdList;
// distanceThresholdList.resize(1);
// distanceThresholdList[0] = 0;
parser->Parse(argc - 4, argv + 4);
std::string inputScalarImageFileName = argv[1];
std::string inputMaskImageFileName = argv[2];
std::string outputLineFilteredImageFileName = argv[3];
sigmaList = parser->ConvertVector<double> (
parser->GetOption("sigma-list")->GetValue());
distanceThresholdList = parser->ConvertVector<double> (
parser->GetOption("distance-threshold-list")->GetValue());
std::cout << "sigma-list: " << std::endl;
PrintVector(sigmaList, std::cout);
std::cout << "distance-threshold-list: " << std::endl;
PrintVector(distanceThresholdList, std::cout);
std::string outputDistanceMapImageFileName = parser->GetOption(
"distance-map-image")->GetValue();
std::string outputHessianImageFileName =
parser->GetOption("hessian-image")->GetValue();
std::string outputScaleImageFileName =
parser->GetOption("scale-image")->GetValue();
// char *inputScalarImageFileName = argv[1];
// char *inputMaskImageFileName = argv[2];
// char *outputLineFilteredImageFileName = argv[3];
// char *outputDistanceMapImageFileName = argv[4];
// char *outputHessianImageFileName = argv[5];
// char *outputScaleImageFileName = argv[6];
// Define the dimension of the images
const unsigned int Dimension = 3;
typedef float InputPixelType;
typedef itk::Image<InputPixelType, Dimension> InputImageType;
typedef unsigned char MaskPixelType;
typedef itk::Image<MaskPixelType, Dimension> MaskImageType;
typedef itk::Image<float, Dimension> DistanceImageType;
typedef float OutputPixelType;
typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
typedef itk::ImageFileReader<InputImageType> FileReaderType;
typedef itk::ImageFileReader<MaskImageType> MaskFileReaderType;
typedef itk::ImageFileWriter<OutputImageType> FileWriterType;
typedef itk::NumericTraits<InputPixelType>::RealType RealPixelType;
typedef itk::SymmetricSecondRankTensor<RealPixelType, Dimension>
HessianPixelType;
typedef itk::Image<HessianPixelType, Dimension> HessianImageType;
// Declare the type of enhancement filter
typedef itk::HessianToShikataMeasureImageFilter<HessianImageType,
InputImageType, OutputImageType> ObjectnessFilterType;
// Declare the type of multiscale enhancement filter
typedef itk::ShikataMultiScaleHessianBasedMeasureImageFilter<
InputImageType, HessianImageType, ObjectnessFilterType,
OutputImageType> MultiScaleEnhancementFilterType;
FileReaderType::Pointer imageReader = FileReaderType::New();
imageReader->SetFileName(inputScalarImageFileName);
try {
imageReader->Update();
} catch (itk::ExceptionObject &ex) {
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
MaskFileReaderType::Pointer maskReader = MaskFileReaderType::New();
maskReader->SetFileName(inputMaskImageFileName);
try {
maskReader->Update();
} catch (itk::ExceptionObject &ex) {
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
ObjectnessFilterType::Pointer objectnessFilter =
ObjectnessFilterType::New();
objectnessFilter->SetScaleObjectnessMeasure(false);
objectnessFilter->SetBrightObject(true);
//generate the distance image here
typedef itk::SignedDanielssonDistanceMapImageFilter<MaskImageType,
DistanceImageType> DistanceMapFilterType;
DistanceMapFilterType::Pointer distanceMapFilter =
DistanceMapFilterType::New();
distanceMapFilter->SetInput(maskReader->GetOutput());
distanceMapFilter->Update();
typedef itk::ShiftScaleInPlaceImageFilter<DistanceImageType>
ScaleFilterType;
ScaleFilterType::Pointer scaleFilter = ScaleFilterType::New();
scaleFilter->SetInput(distanceMapFilter->GetOutput());
scaleFilter->SetScale(-1.0);
scaleFilter->SetShift(0.0);
scaleFilter->Update();
DistanceImageType::Pointer distanceImage = scaleFilter->GetOutput();
MultiScaleEnhancementFilterType::Pointer multiScaleEnhancementFilter =
MultiScaleEnhancementFilterType::New();
multiScaleEnhancementFilter->SetInputScalarImage(imageReader->GetOutput());
multiScaleEnhancementFilter->SetInputDistanceImage(distanceImage);
multiScaleEnhancementFilter->SetSigmaList(sigmaList);
multiScaleEnhancementFilter->SetDistanceThresholdList(distanceThresholdList);
multiScaleEnhancementFilter->SetHessianToMeasureFilter(objectnessFilter);
// multiScaleEnhancementFilter->SetSigmaStepMethodToLogarithmic();
//Change NonNegativeHessianBasedMeasure to Off and regnerate vesselness image
multiScaleEnhancementFilter->NonNegativeHessianBasedMeasureOff();
if (outputScaleImageFileName.compare("") != 0)
multiScaleEnhancementFilter->SetGenerateScalesOutput(true);
if (outputHessianImageFileName.compare("") != 0)
multiScaleEnhancementFilter->SetGenerateHessianOutput(true);
try {
multiScaleEnhancementFilter->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName(outputLineFilteredImageFileName);
writer->UseCompressionOn();
writer->SetInput(multiScaleEnhancementFilter->GetOutput());
try {
writer->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}
if (outputScaleImageFileName.compare("") != 0) {
std::cout << "output scale image:" << outputScaleImageFileName << std::endl;
writer->SetFileName(outputScaleImageFileName);
writer->UseCompressionOn();
writer->SetInput(multiScaleEnhancementFilter->GetScalesOutput());
try {
writer->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}
}
if (outputDistanceMapImageFileName.compare("") != 0) {
std::cout << "output distance map:" << outputDistanceMapImageFileName
<< std::endl;
writer->SetFileName(outputDistanceMapImageFileName);
writer->UseCompressionOn();
writer->SetInput(distanceImage);
try {
writer->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}
}
if (outputHessianImageFileName.compare("") != 0) {
const HessianImageType * hessianImage =
multiScaleEnhancementFilter->GetHessianOutput();
std::cout << "write hessian image to "
<< outputHessianImageFileName << std::endl;
// write the hessian image
typedef itk::ImageFileWriter<HessianImageType> HessianFileWriterType;
HessianFileWriterType::Pointer writer3 = HessianFileWriterType::New();
writer3->SetFileName(outputHessianImageFileName);
writer3->UseCompressionOn();
writer3->SetInput(hessianImage);
try {
writer3->Update();
} catch (itk::ExceptionObject &e) {
std::cerr << e << std::endl;
}
}
return EXIT_SUCCESS;
}