@@ -38,27 +38,27 @@ def test_imread_single_element_list():
3838
3939 try :
4040 # Create and save a test image
41- arr = np .random .randint (0 , 256 , (10 , 10 ), dtype = np .uint8 )
41+ image_size = (8 , 10 )
42+ arr = np .zeros (image_size , dtype = np .uint8 )
4243 image = itk .image_from_array (arr )
4344 itk .imwrite (image , filename )
4445
4546 # Test 1: imread with a string (baseline - should always work)
4647 img_from_string = itk .imread (filename )
4748 assert img_from_string is not None
48- assert itk .size (img_from_string )[0 ] == 10
49- assert itk .size (img_from_string )[1 ] == 10
49+ # NumPy shape (8, 10) becomes ITK size [10, 8] due to row/column-major ordering
50+ assert itk .size (img_from_string )[0 ] == image_size [1 ]
51+ assert itk .size (img_from_string )[1 ] == image_size [0 ]
5052
5153 # Test 2: imread with a single-element list (the bug case)
5254 img_from_list = itk .imread ([filename ])
5355 assert img_from_list is not None
5456 # When reading as a series, dimension is increased by 1
5557 assert img_from_list .GetImageDimension () == 3
56- assert itk .size (img_from_list )[0 ] == 10
57- assert itk .size (img_from_list )[1 ] == 10
58+ assert itk .size (img_from_list )[0 ] == image_size [ 1 ]
59+ assert itk .size (img_from_list )[1 ] == image_size [ 0 ]
5860 assert itk .size (img_from_list )[2 ] == 1
5961
60- print ("✓ Test passed: imread works with single-element list" )
61-
6262 finally :
6363 # Cleanup
6464 if os .path .exists (filename ):
@@ -76,7 +76,8 @@ def test_imread_multi_element_list():
7676
7777 try :
7878 # Create and save test images
79- arr = np .random .randint (0 , 256 , (10 , 10 ), dtype = np .uint8 )
79+ image_size = (8 , 10 )
80+ arr = np .zeros (image_size , dtype = np .uint8 )
8081 image = itk .image_from_array (arr )
8182 itk .imwrite (image , filename1 )
8283 itk .imwrite (image , filename2 )
@@ -86,12 +87,11 @@ def test_imread_multi_element_list():
8687 assert img_from_list is not None
8788 # When reading as a series, dimension is increased by 1
8889 assert img_from_list .GetImageDimension () == 3
89- assert itk .size (img_from_list )[0 ] == 10
90- assert itk .size (img_from_list )[1 ] == 10
90+ # NumPy shape (8, 10) becomes ITK size [10, 8] due to row/column-major ordering
91+ assert itk .size (img_from_list )[0 ] == image_size [1 ]
92+ assert itk .size (img_from_list )[1 ] == image_size [0 ]
9193 assert itk .size (img_from_list )[2 ] == 2
9294
93- print ("✓ Test passed: imread works with multi-element list" )
94-
9595 finally :
9696 # Cleanup
9797 if os .path .exists (filename1 ):
@@ -105,4 +105,3 @@ def test_imread_multi_element_list():
105105if __name__ == "__main__" :
106106 test_imread_single_element_list ()
107107 test_imread_multi_element_list ()
108- print ("\n ✓ All imread list tests passed!" )
0 commit comments