/
test_sct_crop_image.py
61 lines (53 loc) · 1.87 KB
/
test_sct_crop_image.py
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
#!/usr/bin/env python
#########################################################################################
#
# Test function for sct_crop_image
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2017 Polytechnique Montreal <www.neuro.polymtl.ca>
# Author: Julien Cohen-Adad
#
# About the license: see the file LICENSE.TXT
#########################################################################################
from __future__ import absolute_import
from spinalcordtoolbox.image import Image
def init(param_test):
"""
Initialize class: param_test
"""
# initialization
param_test.fname_out = [
't2_crop_xyz.nii',
't2_crop_mask.nii',
't2_crop_ref.nii',
]
default_args = [
'-i t2/t2.nii.gz -o {} -xmin 1 -xmax -3 -ymin 2 -ymax 10'.format(param_test.fname_out[0]),
'-i t2/t2.nii.gz -o {} -m t2/t2_seg.nii.gz'.format(param_test.fname_out[1]),
'-i t2/t2.nii.gz -o {} -ref mt/mt0.nii.gz'.format(param_test.fname_out[2]),
]
# assign default params
if not param_test.args:
param_test.args = default_args
return param_test
def test_integrity(param_test):
"""
Test integrity of function
"""
# find which test is performed
index_args = param_test.default_args.index(param_test.args)
# check if cropping was correct depending on the scenario
if index_args == 0:
xyz = (57, 9, 52)
elif index_args == 1:
xyz = (10, 55, 13)
elif index_args == 2:
xyz = (37, 55, 34)
nx, ny, nz, nt, px, py, pz, pt = Image(param_test.fname_out[index_args]).dim
if (nx, ny, nz) == xyz:
param_test.output += '--> PASSED'
else:
param_test.status = 99
param_test.output += "Output dimensions: {}, {}, {}\n".format(nx, ny, nz)
param_test.output += '--> FAILED'
return param_test