@@ -79,34 +79,23 @@ class TestSpatialCropdStringKeys(unittest.TestCase):
7979 def test_string_roi_start_end (self ):
8080 """String keys for roi_start and roi_end should resolve from data dict."""
8181 img = MetaTensor (torch .rand (3 , 10 , 10 , 10 ))
82- data = {
83- "img" : img ,
84- "roi_start_key" : [0 , 0 , 0 ],
85- "roi_end_key" : [5 , 5 , 5 ],
86- }
82+ data = {"img" : img , "roi_start_key" : [0 , 0 , 0 ], "roi_end_key" : [5 , 5 , 5 ]}
8783 cropper = SpatialCropd (keys = "img" , roi_start = "roi_start_key" , roi_end = "roi_end_key" )
8884 result = cropper (data )
8985 self .assertEqual (result ["img" ].shape , (3 , 5 , 5 , 5 ))
9086
9187 def test_string_roi_center_size (self ):
9288 """String keys for roi_center and roi_size should resolve from data dict."""
9389 img = MetaTensor (torch .rand (1 , 20 , 20 , 20 ))
94- data = {
95- "img" : img ,
96- "center_key" : [10 , 10 , 10 ],
97- "size_key" : [6 , 6 , 6 ],
98- }
90+ data = {"img" : img , "center_key" : [10 , 10 , 10 ], "size_key" : [6 , 6 , 6 ]}
9991 cropper = SpatialCropd (keys = "img" , roi_center = "center_key" , roi_size = "size_key" )
10092 result = cropper (data )
10193 self .assertEqual (result ["img" ].shape , (1 , 6 , 6 , 6 ))
10294
10395 def test_mixed_string_and_direct (self ):
10496 """Mix of string key and direct value for ROI params."""
10597 img = MetaTensor (torch .rand (1 , 20 , 20 , 20 ))
106- data = {
107- "img" : img ,
108- "center_key" : [10 , 10 , 10 ],
109- }
98+ data = {"img" : img , "center_key" : [10 , 10 , 10 ]}
11099 cropper = SpatialCropd (keys = "img" , roi_center = "center_key" , roi_size = [4 , 4 , 4 ])
111100 result = cropper (data )
112101 self .assertEqual (result ["img" ].shape , (1 , 4 , 4 , 4 ))
@@ -175,11 +164,7 @@ def test_string_key_same_as_direct(self):
175164 def test_inverse_with_string_keys (self ):
176165 """Inverse should work correctly when string keys are used."""
177166 img = MetaTensor (torch .rand (1 , 10 , 10 , 10 ))
178- data = {
179- "img" : img ,
180- "start" : [2 , 2 , 2 ],
181- "end" : [6 , 6 , 6 ],
182- }
167+ data = {"img" : img , "start" : [2 , 2 , 2 ], "end" : [6 , 6 , 6 ]}
183168 cropper = SpatialCropd (keys = "img" , roi_start = "start" , roi_end = "end" )
184169 result = cropper (data )
185170 self .assertEqual (result ["img" ].shape , (1 , 4 , 4 , 4 ))
0 commit comments