-
Notifications
You must be signed in to change notification settings - Fork 1.6k
3595 3766 adds a base writer and an itk writer #3674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
dad9365
temp spatial_resample
wyli 0f07fc9
fixes resampling
wyli b09e568
fixes precisions
wyli 0b4bc52
update dict version
wyli 996dacf
fixes unit tests
wyli 2790ca4
adds docs
wyli 4ef11bf
copy grid for resampling
wyli f65605e
fixes unit tests
wyli b3011a7
remove normalize coordinates
wyli a1200dc
[MONAI] python code formatting
monai-bot 7b91be4
try to fix #3621 (#3673)
wyli ec9aaf3
fixes typing
wyli 0ac197f
fixes grid_sample, interpolate URLs
wyli 87ff30b
Merge branch 'fixes-url' into add-spatial-resample
wyli 080f803
Merge remote-tracking branch 'upstream/dev' into add-spatial-resample
wyli aee76ee
simplify norm_coords
wyli 0dc88af
update docstring
wyli d044188
update moveaxis
wyli 7a42452
spatial sample tests
wyli 5ec96a4
additional tests spatial resample
wyli 6509070
test invert saptial resample
wyli 0705aa7
adds a base writer and an itk writer
wyli df2631a
update docstrings
wyli 4419803
remove return self
wyli 4f27d0d
adds reorient_spatial_axes
wyli 9f2d311
update based on comments
wyli f2a2ea9
update based on comments
wyli bc9c705
fixes unit tests
wyli 47bf3e2
Merge remote-tracking branch 'upstream/dev' into add-spatial-resample
wyli 0d93935
Merge branch 'add-spatial-resample' into adds-base-writer-itk-writer
wyli f96614b
sync 3701
wyli bac0b1a
Merge branch 'dev' into adds-base-writer-itk-writer
wyli 5ddcd90
Merge branch 'dev' into adds-base-writer-itk-writer
wyli b32336e
try to fix #3766
wyli 14b9bda
Merge branch 'dev' into adds-base-writer-itk-writer
wyli dbf44ae
revise docstring to be concise
wyli 1f23c04
update based on comments
wyli f49a092
3765 Enhance `create_multigpu_supervised_XXX` for distributed (#3768)
Nic-Ma 9a5fd2e
update to support dynamic spatial_size
wyli fa28672
Merge remote-tracking branch 'upstream/dev' into adds-base-writer-itk…
wyli 9b75f60
update based on comments
wyli d0bdecc
Merge branch 'dev' into adds-base-writer-itk-writer
wyli e71dfb4
Merge branch 'dev' into adds-base-writer-itk-writer
wyli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.