File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 2
2
import numpy as np
3
3
4
4
import pytest
5
- from ..images import update_header_fields , overwrite_header
5
+ from ..images import update_header_fields , overwrite_header , dseg_label
6
6
7
7
8
8
def random_image ():
@@ -71,3 +71,18 @@ def test_overwrite_header_reject_mmap(tmp_path):
71
71
img = nb .load (fname , mmap = True )
72
72
with pytest .raises (ValueError ):
73
73
overwrite_header (img , fname )
74
+
75
+
76
+ def test_dseg_label (tmp_path ):
77
+ fname = str (tmp_path / 'test_file.nii.gz' )
78
+
79
+ data = np .dstack ((
80
+ np .zeros ((20 , 20 ), dtype = 'int16' ),
81
+ np .ones ((20 , 20 ), dtype = 'int16' ),
82
+ np .ones ((20 , 20 ), dtype = 'int16' ) * 2 ,
83
+ np .ones ((20 , 20 ), dtype = 'int16' ) * 3 ,
84
+ ))
85
+ nb .Nifti1Image (data , np .eye (4 ), None ).to_filename (fname )
86
+
87
+ new_im = nb .load (dseg_label (fname , label = 2 ))
88
+ assert np .all ((data == 2 ).astype ('int16' ) == np .int16 (new_im .dataobj ))
You can’t perform that action at this time.
0 commit comments