Skip to content

Commit 4e17965

Browse files
committed
ENH: Test reading ANTs Nifti displacement field metadata
1 parent dca4a36 commit 4e17965

6 files changed

Lines changed: 61 additions & 0 deletions

File tree

Wrapping/Generators/Python/Tests/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ itk_python_add_test(NAME PythonDICOMSeries COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/d
2626
DATA{${ITK_DATA_ROOT}/Input/DicomSeries/Image0076.dcm}
2727
DATA{${ITK_DATA_ROOT}/Input/DicomSeries/Image0077.dcm})
2828
itk_python_add_test(NAME PyImageFilterTest COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/PyImageFilterTest.py)
29+
itk_python_add_test(NAME PythonConvertMetaData COMMAND
30+
${CMAKE_CURRENT_SOURCE_DIR}/test_metadata.py
31+
DATA{${WrapITK_SOURCE_DIR}/images/r16slice.nii.gz}
32+
DATA{${WrapITK_SOURCE_DIR}/images/sourceImage.nii.gz}
33+
DATA{${WrapITK_SOURCE_DIR}/images/warp2D.nii.gz}
34+
DATA{${WrapITK_SOURCE_DIR}/images/warp3D.nii.gz}
35+
)
2936

3037
# some tests will fail if dim=2 and unsigned short are not wrapped
3138
INTERSECTION(WRAP_2 2 "${ITK_WRAP_IMAGE_DIMS}")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ==========================================================================
2+
#
3+
# Copyright NumFOCUS
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0.txt
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# ==========================================================================*/
18+
19+
# Ensure we can convert all Nifti metadata members to Python
20+
21+
import sys
22+
import numpy as np
23+
import pathlib
24+
from pprint import pprint
25+
26+
import itk
27+
28+
nifti_image_2d_filepath = sys.argv[1]
29+
image = itk.imread(nifti_image_2d_filepath)
30+
metadata = dict(image)
31+
print('2D image')
32+
pprint(metadata)
33+
34+
nifti_image_3d_filepath = sys.argv[2]
35+
image = itk.imread(nifti_image_3d_filepath, itk.F)
36+
metadata = dict(image)
37+
print('3D image')
38+
pprint(metadata)
39+
40+
nifti_displacement_2D_filepath = sys.argv[3]
41+
field = itk.imread(nifti_displacement_2D_filepath, itk.F)
42+
metadata = dict(field)
43+
print('2D displacement field')
44+
pprint(metadata)
45+
46+
nifti_displacement_3D_filepath = sys.argv[4]
47+
field = itk.imread(nifti_displacement_3D_filepath, itk.F)
48+
metadata = dict(field)
49+
print('3D displacement field')
50+
pprint(metadata)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ba471888bf8ad9f9230c1b1f3a7874dcb1ccba15439835c2b3b54eb811a9bf948fc255abde7df51e6067f93b7815fdb4b7ae31a4a615bea2fc5893279ab2ccb1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
85827430d88400feaac93141d7e7e1c32f3c885868c769a5385cbaa793044794b586c86cb1f3b285dbc5d274bd43b427c2082a0484cad70bd34d2df29059333b
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fc358313c2478db9bf1edef9159a1647754c525fec4977a51b6baf67145b49f1cb518871397f974e18d55a5627310f1718389547481ba85c4901c62be056ede3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8b57d3dfa1a795bc98aa6d16eadfaaa406445bb84c021dd298e5d3b4aadc0c6109292419d3ed5e58aafcf9d73c18be25ef9492427af433970a5996201673de5c

0 commit comments

Comments
 (0)