-
Notifications
You must be signed in to change notification settings - Fork 3
/
slicer_test.go
572 lines (551 loc) · 21.8 KB
/
slicer_test.go
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
package main
import (
"encoding/xml"
"strings"
"testing"
)
func TestReadXML(t *testing.T) {
var executable Executable
parser := xml.NewDecoder(strings.NewReader(ADXML))
err := parser.Decode(&executable)
if err != nil {
t.Errorf("failed to parse %v", err.Error())
}
if executable.Title != "Anisotropic Diffusion" {
t.Errorf("failed to parse title got '%v'", executable.Title)
}
if len(executable.ParameterGroups) != 2 {
t.Errorf("incorrect number of parameter groups found '%v'", len(executable.ParameterGroups))
}
}
func TestParseService(t *testing.T) {
for _, tt := range serviceTests {
s, err := CreateServiceFromXML(tt.executable, tt.xml)
if err != nil {
t.Errorf("failed to parse %v", err.Error())
}
if len(s.Parameters) != tt.parameter_count {
t.Errorf("%v unexpected commandline length expected: %v actual: %v -- %v", tt.executable, tt.parameter_count, len(s.Parameters), s.Parameters)
}
if len(s.OutputFiles) != tt.output_file_count {
t.Errorf("%v unexpected output file length expected: %v actual: %v -- %v", tt.executable, tt.output_file_count, len(s.OutputFiles), s.OutputFiles)
}
if len(s.InputFiles) != tt.input_file_count {
t.Errorf("%v unexpected input file length expected: %v actual: %v -- %v", tt.executable, tt.input_file_count, len(s.InputFiles), s.InputFiles)
}
for param, doc := range tt.parameter_descriptions {
v, ok := s.ParameterDescriptions[param]
if !ok {
t.Errorf("%v did not find expected description for %v (%v)", tt.executable, param, doc)
}
if v != doc {
t.Errorf("%v incorrect description for %v expected: %v got: %v", tt.executable, param, doc, v)
}
}
}
}
var serviceTests = []struct {
title string
executable string
parameter_count int
input_file_count int
output_file_count int
xml string
parameter_descriptions map[string]string // Test the descriptions
}{
{"Anisotropic Diffusion", "AnisotropicDiffusion", 3, 1, 1, ADXML, map[string]string{
"conductance": "Conductance",
"timeStep": "Time Step",
}},
{"Gradient Anisotropic Diffusion", "GradientAnisotropicDiffusion", 4, 1, 1, GADXML, map[string]string{
"conductance": "Conductance controls the sensitivity of the conductance term. As a general rule, the lower the value, the more strongly the filter preserves edges. A high value will cause diffusion (smoothing) across edges. Note that the number of iterations controls how much smoothing is done within regions bounded by edges.",
"timeStep": "The time step depends on the dimensionality of the image. In Slicer the images are 3D and the default (.0625) time step will provide a stable solution.",
}},
{"Tour", "ExecutionModelTour", 10, 2, 4, TourXML, map[string]string{
"integerVariable": "An integer without constraints",
"doubleVariable": "A double with constraints",
}},
// NB: this is an error, the segimage2itkimage has a bug! The OutputDirName should be an "output" channel
{"Seg Image 2 ITK Image", "segimage2itkimage", 2, 2, 0, segimage2itkimageXML, map[string]string{
"prefix": "Prefix for output file.",
}},
}
// These XML strings are from the Slicer CLI modules and website examples.
var ADXML = `<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>filtering</category>
<title>Anisotropic Diffusion</title>
<description>
Runs anisotropic diffusion on a volume
</description>
<version>1.0</version>
<documentation-url></documentation-url>
<license></license>
<contributor>Bill Lorensen</contributor>
<parameters>
<label>
Anisotropic Diffusion Parameters
</label>
<description>
Parameters for the anisotropic
diffusion algorithm
</description>
<double>
<name>conductance</name>
<longflag>conductance</longflag>
<description>Conductance</description>
<label>Conductance</label>
<default>1</default>
<constraints>
<minimum>0</minimum>
<maximum>10</maximum>
<step>.01</step>
</constraints>
</double>
<double>
<name>timeStep</name>
<longflag>timeStep</longflag>
<description>Time Step</description>
<label>Time Step</label>
<default>0.0625</default>
<constraints>
<minimum>.001</minimum>
<maximum>1</maximum>
<step>.001</step>
</constraints>
</double>
<integer>
<name>numberOfIterations</name>
<longflag>iterations</longflag>
<description>Number of iterations</description>
<label>Iterations</label>
<default>1</default>
<constraints>
<minimum>1</minimum>
<maximum>30</maximum>
<step>1</step>
</constraints>
</integer>
</parameters>
<parameters>
<label>IO</label>
<description>Input/output parameters</description>
<image>
<name>inputVolume</name>
<label>Input Volume</label>
<channel>input</channel>
<index>0</index>
<description>Input volume to be filtered</description>
</image>
<image>
<name>outputVolume</name>
<label>Output Volume</label>
<channel>output</channel>
<index>1</index>
<description>Output filtered</description>
</image>
</parameters>
</executable>`
var GADXML = `<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Filtering.Denoising</category>
<index>1</index>
<title>Gradient Anisotropic Diffusion</title>
<description><![CDATA[Runs gradient anisotropic diffusion on a volume.
Anisotropic diffusion methods reduce noise (or unwanted detail) in images while preserving specific image features, like edges. For many applications, there is an assumption that light-dark transitions (edges) are interesting. Standard isotropic diffusion methods move and blur light-dark boundaries. Anisotropic diffusion methods are formulated to specifically preserve edges. The conductance term for this implementation is a function of the gradient magnitude of the image at each point, reducing the strength of diffusion at edges. The numerical implementation of this equation is similar to that described in the Perona-Malik paper, but uses a more robust technique for gradient magnitude estimation and has been generalized to N-dimensions.]]></description>
<version>0.1.0.$Revision: 24424 $(alpha)</version>
<documentation-url>http://wiki.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/GradientAnisotropicDiffusion</documentation-url>
<license/>
<contributor>Bill Lorensen (GE)</contributor>
<acknowledgements><![CDATA[This command module was derived from Insight/Examples (copyright) Insight Software Consortium]]></acknowledgements>
<parameters>
<label>Anisotropic Diffusion Parameters</label>
<description><![CDATA[Parameters for the anisotropic diffusion algorithm]]></description>
<double>
<name>conductance</name>
<longflag>--conductance</longflag>
<description><![CDATA[Conductance controls the sensitivity of the conductance term. As a general rule, the lower the value, the more strongly the filter preserves edges. A high value will cause diffusion (smoothing) across edges. Note that the number of iterations controls how much smoothing is done within regions bounded by edges.]]></description>
<label>Conductance</label>
<default>1</default>
<constraints>
<minimum>0</minimum>
<maximum>10</maximum>
<step>.01</step>
</constraints>
</double>
<integer>
<name>numberOfIterations</name>
<longflag>--iterations</longflag>
<description><![CDATA[The more iterations, the more smoothing. Each iteration takes the same amount of time. If it takes 10 seconds for one iteration, then it will take 100 seconds for 10 iterations. Note that the conductance controls how much each iteration smooths across edges.]]></description>
<label>Iterations</label>
<default>5</default>
<constraints>
<minimum>1</minimum>
<maximum>30</maximum>
<step>1</step>
</constraints>
</integer>
<double>
<name>timeStep</name>
<longflag>--timeStep</longflag>
<description><![CDATA[The time step depends on the dimensionality of the image. In Slicer the images are 3D and the default (.0625) time step will provide a stable solution.]]></description>
<label>Time Step</label>
<default>0.0625</default>
<constraints>
<minimum>.001</minimum>
<maximum>.0625</maximum>
<step>.001</step>
</constraints>
</double>
</parameters>
<parameters>
<label>IO</label>
<description><![CDATA[Input/output parameters]]></description>
<image>
<name>inputVolume</name>
<label>Input Volume</label>
<channel>input</channel>
<index>0</index>
<description><![CDATA[Input volume to be filtered]]></description>
</image>
<image>
<name>outputVolume</name>
<label>Output Volume</label>
<channel>output</channel>
<index>1</index>
<description><![CDATA[Output filtered]]></description>
</image>
</parameters>
<parameters advanced = "true">
<label>Advanced</label>
<description><![CDATA[Advanced parameters for the anisotropic diffusion algorithm]]></description>
<boolean>
<name>useImageSpacing</name>
<longflag>--useImageSpacing</longflag>
<description>![CDATA[Take into account image spacing in the computation. It is advisable to turn this option on, especially when the pixel size is different in different dimensions. However, to produce results consistent with Slicer4.2 and earlier, this option should be turned off.]]</description>
<label>Use image spacing</label>
<default>true</default>
</boolean>
</parameters>
</executable>
`
var TourXML = `<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Developer Tools</category>
<title>Execution Model Tour</title>
<description><![CDATA[Shows one of each type of parameter.]]></description>
<version>0.1.0.$Revision: 24459 $(alpha)</version>
<documentation-url>http://wiki.slicer.org/slicerWiki/index.php/Documentation/Nightly/Modules/ExecutionModelTour</documentation-url>
<license/>
<contributor>Daniel Blezek (GE), Bill Lorensen (GE)</contributor>
<acknowledgements><![CDATA[This work is part of the National Alliance for Medical Image Computing (NAMIC), funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB005149.]]></acknowledgements>
<parameters>
<label>Scalar Parameters</label>
<description><![CDATA[Variations on scalar parameters]]></description>
<integer>
<name>integerVariable</name>
<flag>-i</flag>
<longflag>--integer</longflag>
<description><![CDATA[An integer without constraints]]></description>
<label>Integer Parameter</label>
<default>30</default>
</integer>
<double>
<name>doubleVariable</name>
<flag>-d</flag>
<longflag>--double</longflag>
<description><![CDATA[A double with constraints]]></description>
<label>Double Parameter</label>
<default>30</default>
<constraints>
<minimum>0</minimum>
<maximum>1.e3</maximum>
<step>10</step>
</constraints>
</double>
</parameters>
<parameters>
<label>Vector Parameters</label>
<description><![CDATA[Variations on vector parameters]]></description>
<float-vector>
<name>floatVector</name>
<flag>f</flag>
<description><![CDATA[A vector of floats]]></description>
<label>Float Vector Parameter</label>
<default>1.3,2,-14</default>
</float-vector>
<string-vector>
<name>stringVector</name>
<longflag>string_vector</longflag>
<description><![CDATA[A vector of strings]]></description>
<label>String Vector Parameter</label>
<default>foo,bar,foobar</default>
</string-vector>
</parameters>
<parameters>
<label>Enumeration Parameters</label>
<description><![CDATA[Variations on enumeration parameters]]></description>
<string-enumeration>
<name>stringChoice</name>
<flag>e</flag>
<longflag>enumeration</longflag>
<description><![CDATA[An enumeration of strings]]></description>
<label>String Enumeration Parameter</label>
<default>Bill</default>
<element>Ron</element>
<element>Eric</element>
<element>Bill</element>
<element>Ross</element>
<element>Steve</element>
<element>Will</element>
</string-enumeration>
</parameters>
<parameters>
<label>Boolean Parameters</label>
<description><![CDATA[Variations on boolean parameters]]></description>
<boolean>
<name>boolean1</name>
<longflag>boolean1</longflag>
<description><![CDATA[A boolean default true]]></description>
<label>Boolean Default true</label>
<default>true</default>
</boolean>
<boolean>
<name>boolean2</name>
<longflag>boolean2</longflag>
<description><![CDATA[A boolean default false]]></description>
<label>Boolean Default false</label>
<default>false</default>
</boolean>
<boolean>
<name>boolean3</name>
<longflag>boolean3</longflag>
<description><![CDATA[A boolean with no default, should be defaulting to false]]></description>
<label>Boolean No Default</label>
</boolean>
</parameters>
<parameters>
<label>File, Directory and Image Parameters</label>
<description><![CDATA[Parameters that describe files and direcories.]]></description>
<file fileExtensions=".png,.jpg,.jpeg,.bmp,.tif,.tiff,.gipl,.dcm,.dicom,.nhdr,.nrrd,.mhd,.mha,.mask,.hdr,.nii,.nii.gz,.hdr.gz,.pic,.lsm,.spr,.vtk,.vtkp,.vtki,.stl,.csv,.txt,.xml,.html">
<longflag>file1</longflag>
<description><![CDATA[An input file]]></description>
<label>Input file</label>
<channel>input</channel>
</file>
<file fileExtensions=".png,.jpg,.jpeg,.bmp,.tif,.tiff,.gipl,.dcm,.dicom,.nhdr,.nrrd,.mhd,.mha,.mask,.hdr,.nii,.nii.gz,.hdr.gz,.pic,.lsm,.spr,.vtk,.vtkp,.vtki,.stl,.csv,.txt,.xml,.html" multiple="true">
<longflag>files</longflag>
<description><![CDATA[Multiple input files]]></description>
<label>Input Files</label>
<channel>input</channel>
</file>
<directory>
<longflag>directory1</longflag>
<description><![CDATA[An input directory. If no default is specified, the current directory is used,]]></description>
<label>Input directory</label>
<channel>input</channel>
</directory>
<image>
<longflag>image1</longflag>
<description><![CDATA[An input image]]></description>
<label>Input image</label>
<channel>input</channel>
</image>
<image>
<longflag>image2</longflag>
<description><![CDATA[An output image]]></description>
<label>Output image</label>
<channel>output</channel>
</image>
<transform type="linear">
<longflag>transform1</longflag>
<description><![CDATA[An input transform]]></description>
<label>Input transform</label>
<channel>input</channel>
</transform>
<transform type="linear">
<longflag>transform2</longflag>
<description><![CDATA[An output transform]]></description>
<label>Output transform</label>
<channel>output</channel>
</transform>
<point multiple="true" coordinateSystem="ras">
<name>seed</name>
<label>Seeds</label>
<longflag>--seed</longflag>
<description><![CDATA[Lists of points in the CLI correspond to slicer fiducial lists]]></description>
<default>0,0,0</default>
</point>
<pointfile multiple="true" fileExtensions=".fcsv" coordinateSystem="lps">
<name>seedsFile</name>
<description><![CDATA[Test file of input fiducials, compared to seeds]]></description>
<label>Seeds file</label>
<longflag>seedsFile</longflag>
<channel>input</channel>
</pointfile>
</parameters>
<parameters>
<label>Index Parameters</label>
<description><![CDATA[Variations on parameters that use index rather than flags.]]></description>
<image>
<name>arg0</name>
<channel>input</channel>
<index>0</index>
<description><![CDATA[First index argument is an image]]></description>
<label>First index argument</label>
</image>
<image>
<name>arg1</name>
<channel>output</channel>
<index>1</index>
<description><![CDATA[Second index argument is an image]]></description>
<label>Second index argument</label>
</image>
</parameters>
<parameters>
<label>Regions of interest</label>
<region multiple="true">
<name>regions</name>
<label>Region list</label>
<longflag>region</longflag>
<description><![CDATA[List of regions to process]]></description>
</region>
</parameters>
<parameters>
<label>Measurements</label>
<measurement>
<name>inputFA</name>
<channel>input</channel>
<label>Input FA measurements</label>
<longflag>inputFA</longflag>
<description><![CDATA[Array of FA values to process]]></description>
</measurement>
<measurement>
<name>outputFA</name>
<channel>output</channel>
<label>Output FA measurements</label>
<longflag>outputFA</longflag>
<description><![CDATA[Array of processed (output) FA values]]></description>
</measurement>
</parameters>
<parameters>
<label>Simple return types</label>
<integer>
<name>anintegerreturn</name>
<label>An integer return value</label>
<channel>output</channel>
<default>5</default>
<description><![CDATA[An example of an integer return type]]></description>
</integer>
<boolean>
<name>abooleanreturn</name>
<label>A boolean return value</label>
<channel>output</channel>
<default>false</default>
<description><![CDATA[An example of a boolean return type]]></description>
</boolean>
<float>
<name>afloatreturn</name>
<label>A floating point return value</label>
<channel>output</channel>
<default>7.0</default>
<description><![CDATA[An example of a float return type]]></description>
</float>
<double>
<name>adoublereturn</name>
<label>A double point return value</label>
<channel>output</channel>
<default>14.0</default>
<description><![CDATA[An example of a double return type]]></description>
</double>
<string>
<name>astringreturn</name>
<label>A string point return value</label>
<channel>output</channel>
<default>Hello</default>
<description><![CDATA[An example of a string return type]]></description>
</string>
<integer-vector>
<name>anintegervectorreturn</name>
<label>An integer vector return value</label>
<channel>output</channel>
<default>1,2,3</default>
<description><![CDATA[An example of an integer vector return type]]></description>
</integer-vector>
<string-enumeration>
<name>astringchoicereturn</name>
<channel>output</channel>
<description><![CDATA[An enumeration of strings as a return type]]></description>
<label>A string enumeration return value</label>
<default>Bill</default>
<element>Ron</element>
<element>Eric</element>
<element>Bill</element>
<element>Ross</element>
<element>Steve</element>
<element>Will</element>
</string-enumeration>
</parameters>
<parameters>
<label>File return types</label>
<pointfile fileExtensions=".fcsv" coordinateSystem="lps">
<name>seedsOutFile</name>
<label>Output Fiducials File</label>
<description><![CDATA[Output file to read back in, compare to seeds with flipped settings on first fiducial]]></description>
<longflag>seedsOutFile</longflag>
<channel>output</channel>
</pointfile>
</parameters>
</executable>
`
var segimage2itkimageXML = `<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Informatics</category>
<title>Convert DICOM SEG into ITK image</title>
<description>This tool can be used to convert DICOM Segmentation into volumetric segmentations stored as labeled pixels using research format, such as NRRD or NIfTI, and meta information stored in the JSON file format.</description>
<version>1.0</version>
<documentation-url>https://github.com/QIICR/dcmqi</documentation-url>
<license></license>
<contributor>Andrey Fedorov(BWH), Christian Herz(BWH)</contributor>
<acknowledgements>This work is supported in part the National Institutes of Health, National Cancer Institute, Informatics Technology for Cancer Research (ITCR) program, grant Quantitative Image Informatics for Cancer Research (QIICR) (U24 CA180918, PIs Kikinis and Fedorov).</acknowledgements>
<parameters>
<file>
<name>inputSEGFileName</name>
<label>SEG file name</label>
<channel>input</channel>
<longflag>inputDICOM</longflag>
<description>File name of the input DICOM Segmentation image object.</description>
</file>
<file>
<name>outputDirName</name>
<label>Output directory name</label>
<channel>input</channel>
<longflag>outputDirectory</longflag>
<description>Directory to store individual segments saved using the output format specified files. When specified, file names will contain prefix, followed by the segment number.</description>
</file>
<string>
<name>prefix</name>
<label>Output prefix</label>
<flag>p</flag>
<longflag>prefix</longflag>
<description>Prefix for output file.</description>
<default></default>
</string>
<string-enumeration>
<name>outputType</name>
<flag>t</flag>
<longflag>outputType</longflag>
<description>Output file format for the resulting image data.</description>
<label>Output type</label>
<default>nrrd</default>
<element>nrrd</element>
<element>mhd</element>
<element>mha</element>
<element>nii</element>
<element>nifti</element>
<element>hdr</element>
<element>img</element>
</string-enumeration>
</parameters>
</executable>
`