Skip to content

Commit fb1009e

Browse files
committed
TEST: Initial crop_image test
1 parent bbd83d7 commit fb1009e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

nibabel/tests/test_funcs.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import numpy as np
1313

14-
from ..funcs import concat_images, as_closest_canonical, OrientationError
14+
from ..funcs import concat_images, as_closest_canonical, OrientationError, crop_image
1515
from ..analyze import AnalyzeImage
1616
from ..nifti1 import Nifti1Image
1717
from ..loadsave import save
@@ -193,3 +193,22 @@ def test_closest_canonical():
193193
img.header.set_dim_info(None, None, 2)
194194
xyz_img = as_closest_canonical(img)
195195
assert_true(xyz_img.header.get_dim_info() == (None, None, 1))
196+
197+
198+
def test_crop_image():
199+
# Use 32-bit data so that the AnalyzeImage class doesn't complain
200+
arr = np.arange(60).reshape((5, 3, 4, 1)).astype(np.int32)
201+
202+
img = AnalyzeImage(arr, np.eye(4))
203+
204+
cropped_img = crop_image(img, [[1, 3], [1, 1], [1, 2]])
205+
assert_equal(cropped_img.shape, (3, 1, 2, 1))
206+
assert_array_equal(cropped_img.affine, [[1, 0, 0, 1],
207+
[0, 1, 0, 1],
208+
[0, 0, 1, 1],
209+
[0, 0, 0, 1]])
210+
211+
cropped_img = crop_image(img, [[1, 3], [1, 1], [1, 2]], margin=1)
212+
assert_equal(cropped_img.shape, (5, 3, 4, 1))
213+
assert_array_equal(cropped_img.affine, img.affine)
214+
assert_true(cropped_img is img)

0 commit comments

Comments
 (0)