-
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.
3595 3766 adds a base writer and an itk writer (#3674)
* temp spatial_resample Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes resampling Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes precisions Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update dict version Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes unit tests Signed-off-by: Wenqi Li <wenqil@nvidia.com> * adds docs Signed-off-by: Wenqi Li <wenqil@nvidia.com> * copy grid for resampling Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes unit tests Signed-off-by: Wenqi Li <wenqil@nvidia.com> * remove normalize coordinates Signed-off-by: Wenqi Li <wenqil@nvidia.com> * [MONAI] python code formatting Signed-off-by: monai-bot <monai.miccai2019@gmail.com> * try to fix #3621 (#3673) Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes typing Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes grid_sample, interpolate URLs Signed-off-by: Wenqi Li <wenqil@nvidia.com> * simplify norm_coords Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update docstring Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update moveaxis Signed-off-by: Wenqi Li <wenqil@nvidia.com> * spatial sample tests Signed-off-by: Wenqi Li <wenqil@nvidia.com> * additional tests spatial resample Signed-off-by: Wenqi Li <wenqil@nvidia.com> * test invert saptial resample Signed-off-by: Wenqi Li <wenqil@nvidia.com> * adds a base writer and an itk writer Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update docstrings Signed-off-by: Wenqi Li <wenqil@nvidia.com> * remove return self Signed-off-by: Wenqi Li <wenqil@nvidia.com> * adds reorient_spatial_axes Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update based on comments Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update based on comments Signed-off-by: Wenqi Li <wenqil@nvidia.com> * fixes unit tests Signed-off-by: Wenqi Li <wenqil@nvidia.com> * sync 3701 Signed-off-by: Wenqi Li <wenqil@nvidia.com> * try to fix #3766 Signed-off-by: Wenqi Li <wenqil@nvidia.com> * revise docstring to be concise Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update based on comments Signed-off-by: Wenqi Li <wenqil@nvidia.com> * 3765 Enhance `create_multigpu_supervised_XXX` for distributed (#3768) * [DLMED] add check for devices Signed-off-by: Nic Ma <nma@nvidia.com> * [DLMED] update according to comments Signed-off-by: Nic Ma <nma@nvidia.com> * update to support dynamic spatial_size Signed-off-by: Wenqi Li <wenqil@nvidia.com> * update based on comments Signed-off-by: Wenqi Li <wenqil@nvidia.com>
- Loading branch information
Showing
9 changed files
with
606 additions
and
45 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,55 @@ | ||
# 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. | ||
|
||
import os | ||
import tempfile | ||
import unittest | ||
|
||
import numpy as np | ||
import torch | ||
|
||
from monai.data import ITKWriter | ||
from monai.utils import optional_import | ||
|
||
itk, has_itk = optional_import("itk") | ||
nib, has_nibabel = optional_import("nibabel") | ||
|
||
|
||
@unittest.skipUnless(has_itk, "Requires `itk` package.") | ||
class TestITKWriter(unittest.TestCase): | ||
def test_channel_shape(self): | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
for c in (0, 1, 2, 3): | ||
fname = os.path.join(tempdir, f"testing{c}.nii") | ||
itk_writer = ITKWriter() | ||
itk_writer.set_data_array(torch.zeros(1, 2, 3, 4), channel_dim=c, squeeze_end_dims=False) | ||
itk_writer.set_metadata({}) | ||
itk_writer.write(fname) | ||
itk_obj = itk.imread(fname) | ||
s = [1, 2, 3, 4] | ||
s.pop(c) | ||
np.testing.assert_allclose(itk.size(itk_obj), s) | ||
|
||
def test_rgb(self): | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
fname = os.path.join(tempdir, "testing.png") | ||
writer = ITKWriter(output_dtype=np.uint8) | ||
writer.set_data_array(np.arange(48).reshape(3, 4, 4), channel_dim=0) | ||
writer.set_metadata({"spatial_shape": (5, 5)}) | ||
writer.write(fname) | ||
|
||
output = np.asarray(itk.imread(fname)) | ||
np.testing.assert_allclose(output.shape, (5, 5, 3)) | ||
np.testing.assert_allclose(output[1, 1], (5, 5, 4)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.