-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RandSimulateLowResolution(d) array and dictionary transforms an…
…d corresponding unit tests (#6806) Fixes #3781. ### Description Random simulation of low resolution corresponding to nnU-Net's (https://github.com/MIC-DKFZ/batchgenerators/blob/7651ece69faf55263dd582a9f5cbd149ed9c3ad0/batchgenerators/transforms/resample_transforms.py#L23). First, the array/tensor is resampled at lower resolution as determined by the zoom_factor which is uniformly sampled from the `zoom_range`. Then, the array/tensor is resampled at the original resolution. MONAI's `Resize` transform is used for the resampling operations. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [x] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Aaron Kujawa <askujawa@gmail.com>
- Loading branch information
1 parent
4c22a27
commit d6bafc9
Showing
6 changed files
with
360 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) MONAI Consortium | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import annotations | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
from parameterized import parameterized | ||
|
||
from monai.transforms import RandSimulateLowResolution | ||
from tests.utils import TEST_NDARRAYS, assert_allclose | ||
|
||
TESTS = [] | ||
for p in TEST_NDARRAYS: | ||
TESTS.append( | ||
[ | ||
dict(prob=1.0, zoom_range=(0.8, 0.81)), | ||
p( | ||
np.array( | ||
[ | ||
[ | ||
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], | ||
[[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]], | ||
[[32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47]], | ||
[[48, 49, 50, 51], [52, 53, 54, 55], [56, 57, 58, 59], [60, 61, 62, 63]], | ||
] | ||
] | ||
) | ||
), | ||
np.array( | ||
[ | ||
[ | ||
[ | ||
[0.0000, 0.6250, 1.3750, 2.0000], | ||
[2.5000, 3.1250, 3.8750, 4.5000], | ||
[5.5000, 6.1250, 6.8750, 7.5000], | ||
[8.0000, 8.6250, 9.3750, 10.0000], | ||
], | ||
[ | ||
[10.0000, 10.6250, 11.3750, 12.0000], | ||
[12.5000, 13.1250, 13.8750, 14.5000], | ||
[15.5000, 16.1250, 16.8750, 17.5000], | ||
[18.0000, 18.6250, 19.3750, 20.0000], | ||
], | ||
[ | ||
[22.0000, 22.6250, 23.3750, 24.0000], | ||
[24.5000, 25.1250, 25.8750, 26.5000], | ||
[27.5000, 28.1250, 28.8750, 29.5000], | ||
[30.0000, 30.6250, 31.3750, 32.0000], | ||
], | ||
[ | ||
[32.0000, 32.6250, 33.3750, 34.0000], | ||
[34.5000, 35.1250, 35.8750, 36.5000], | ||
[37.5000, 38.1250, 38.8750, 39.5000], | ||
[40.0000, 40.6250, 41.3750, 42.0000], | ||
], | ||
] | ||
] | ||
), | ||
] | ||
) | ||
|
||
|
||
class TestRandGaussianSmooth(unittest.TestCase): | ||
@parameterized.expand(TESTS) | ||
def test_value(self, arguments, image, expected_data): | ||
randsimlowres = RandSimulateLowResolution(**arguments) | ||
randsimlowres.set_random_state(seed=0) | ||
result = randsimlowres(image) | ||
assert_allclose(result, expected_data, rtol=1e-4, type_test="tensor") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.