|
141 | 141 |
|
142 | 142 | DATA_12 = {"image": np.arange(27).reshape(3, 3, 3), PostFix.meta("image"): {}, "guidance": [[0, 0, 0], [0, 1, 1], 1]} |
143 | 143 |
|
| 144 | +DATA_13 = { |
| 145 | + "image": np.arange(64).reshape((1, 4, 4, 4)), |
| 146 | + PostFix.meta("image"): { |
| 147 | + "spatial_shape": [8, 8, 4], |
| 148 | + "foreground_start_coord": np.array([1, 1, 1]), |
| 149 | + "foreground_end_coord": np.array([3, 3, 3]), |
| 150 | + "foreground_original_shape": (1, 4, 4, 4), |
| 151 | + "foreground_cropped_shape": (1, 2, 2, 2), |
| 152 | + "original_affine": np.array( |
| 153 | + [[[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]] |
| 154 | + ), |
| 155 | + }, |
| 156 | + "pred": np.array([[[[10, 20], [30, 40]], [[50, 60], [70, 80]]]]), |
| 157 | +} |
| 158 | + |
144 | 159 | FIND_SLICE_TEST_CASE_1 = [{"label": "label", "sids": "sids"}, DATA_1, [0]] |
145 | 160 |
|
146 | 161 | FIND_SLICE_TEST_CASE_2 = [{"label": "label", "sids": "sids"}, DATA_2, [0, 1]] |
|
329 | 344 |
|
330 | 345 | RESTORE_LABEL_TEST_CASE_2 = [{"keys": ["pred"], "ref_image": "image", "mode": "nearest"}, DATA_11, RESULT] |
331 | 346 |
|
| 347 | +RESTORE_LABEL_TEST_CASE_3_RESULT = np.zeros((10, 20, 20)) |
| 348 | +RESTORE_LABEL_TEST_CASE_3_RESULT[:5, 0:10, 0:10] = 1 |
| 349 | +RESTORE_LABEL_TEST_CASE_3_RESULT[:5, 0:10, 10:20] = 2 |
| 350 | +RESTORE_LABEL_TEST_CASE_3_RESULT[:5, 10:20, 0:10] = 3 |
| 351 | +RESTORE_LABEL_TEST_CASE_3_RESULT[:5, 10:20, 10:20] = 4 |
| 352 | +RESTORE_LABEL_TEST_CASE_3_RESULT[5:10, 0:10, 0:10] = 5 |
| 353 | +RESTORE_LABEL_TEST_CASE_3_RESULT[5:10, 0:10, 10:20] = 6 |
| 354 | +RESTORE_LABEL_TEST_CASE_3_RESULT[5:10, 10:20, 0:10] = 7 |
| 355 | +RESTORE_LABEL_TEST_CASE_3_RESULT[5:10, 10:20, 10:20] = 8 |
| 356 | + |
| 357 | +RESTORE_LABEL_TEST_CASE_3 = [ |
| 358 | + {"keys": ["pred"], "ref_image": "image", "mode": "nearest", "restore_cropping": False}, |
| 359 | + DATA_11, |
| 360 | + RESTORE_LABEL_TEST_CASE_3_RESULT, |
| 361 | +] |
| 362 | + |
| 363 | +RESTORE_LABEL_TEST_CASE_4_RESULT = np.zeros((4, 8, 8)) |
| 364 | +RESTORE_LABEL_TEST_CASE_4_RESULT[1, 2:6, 2:6] = np.array( |
| 365 | + [[10.0, 10.0, 20.0, 20.0], [10.0, 10.0, 20.0, 20.0], [30.0, 30.0, 40.0, 40.0], [30.0, 30.0, 40.0, 40.0]] |
| 366 | +) |
| 367 | +RESTORE_LABEL_TEST_CASE_4_RESULT[2, 2:6, 2:6] = np.array( |
| 368 | + [[50.0, 50.0, 60.0, 60.0], [50.0, 50.0, 60.0, 60.0], [70.0, 70.0, 80.0, 80.0], [70.0, 70.0, 80.0, 80.0]] |
| 369 | +) |
| 370 | + |
| 371 | +RESTORE_LABEL_TEST_CASE_4 = [ |
| 372 | + {"keys": ["pred"], "ref_image": "image", "mode": "nearest", "restore_resizing": False}, |
| 373 | + DATA_13, |
| 374 | + RESTORE_LABEL_TEST_CASE_4_RESULT, |
| 375 | +] |
| 376 | + |
| 377 | +RESTORE_LABEL_TEST_CASE_5_RESULT = np.zeros((4, 4, 4)) |
| 378 | +RESTORE_LABEL_TEST_CASE_5_RESULT[1, 1:3, 1:3] = np.array([[10.0, 20.0], [30.0, 40.0]]) |
| 379 | +RESTORE_LABEL_TEST_CASE_5_RESULT[2, 1:3, 1:3] = np.array([[50.0, 60.0], [70.0, 80.0]]) |
| 380 | + |
| 381 | +RESTORE_LABEL_TEST_CASE_5 = [ |
| 382 | + {"keys": ["pred"], "ref_image": "image", "mode": "nearest", "restore_spacing": False}, |
| 383 | + DATA_13, |
| 384 | + RESTORE_LABEL_TEST_CASE_5_RESULT, |
| 385 | +] |
| 386 | + |
| 387 | +RESTORE_LABEL_TEST_CASE_6_RESULT = np.zeros((1, 4, 8, 8)) |
| 388 | +RESTORE_LABEL_TEST_CASE_6_RESULT[-1, 1, 2:6, 2:6] = np.array( |
| 389 | + [[10.0, 10.0, 20.0, 20.0], [10.0, 10.0, 20.0, 20.0], [30.0, 30.0, 40.0, 40.0], [30.0, 30.0, 40.0, 40.0]] |
| 390 | +) |
| 391 | +RESTORE_LABEL_TEST_CASE_6_RESULT[-1, 2, 2:6, 2:6] = np.array( |
| 392 | + [[50.0, 50.0, 60.0, 60.0], [50.0, 50.0, 60.0, 60.0], [70.0, 70.0, 80.0, 80.0], [70.0, 70.0, 80.0, 80.0]] |
| 393 | +) |
| 394 | + |
| 395 | +RESTORE_LABEL_TEST_CASE_6 = [ |
| 396 | + {"keys": ["pred"], "ref_image": "image", "mode": "nearest", "restore_slicing": False}, |
| 397 | + DATA_13, |
| 398 | + RESTORE_LABEL_TEST_CASE_6_RESULT, |
| 399 | +] |
| 400 | + |
| 401 | +RESTORE_LABEL_TEST_CASE_7 = [ |
| 402 | + { |
| 403 | + "keys": ["pred"], |
| 404 | + "ref_image": "image", |
| 405 | + "mode": "nearest", |
| 406 | + "restore_resizing": False, |
| 407 | + "restore_cropping": False, |
| 408 | + "restore_spacing": False, |
| 409 | + "restore_slicing": False, |
| 410 | + }, |
| 411 | + DATA_11, |
| 412 | + np.array([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]), |
| 413 | +] |
| 414 | + |
332 | 415 | FETCH_2D_SLICE_TEST_CASE_1 = [ |
333 | 416 | {"keys": ["image"], "guidance": "guidance"}, |
334 | 417 | DATA_12, |
@@ -445,7 +528,17 @@ def test_correct_results(self, arguments, input_data, expected_result): |
445 | 528 |
|
446 | 529 | class TestRestoreLabeld(unittest.TestCase): |
447 | 530 |
|
448 | | - @parameterized.expand([RESTORE_LABEL_TEST_CASE_1, RESTORE_LABEL_TEST_CASE_2]) |
| 531 | + @parameterized.expand( |
| 532 | + [ |
| 533 | + RESTORE_LABEL_TEST_CASE_1, |
| 534 | + RESTORE_LABEL_TEST_CASE_2, |
| 535 | + RESTORE_LABEL_TEST_CASE_3, |
| 536 | + RESTORE_LABEL_TEST_CASE_4, |
| 537 | + RESTORE_LABEL_TEST_CASE_5, |
| 538 | + RESTORE_LABEL_TEST_CASE_6, |
| 539 | + RESTORE_LABEL_TEST_CASE_7, |
| 540 | + ] |
| 541 | + ) |
449 | 542 | def test_correct_results(self, arguments, input_data, expected_result): |
450 | 543 | result = RestoreLabeld(**arguments)(input_data) |
451 | 544 | np.testing.assert_allclose(result["pred"], expected_result) |
|
0 commit comments