-
Notifications
You must be signed in to change notification settings - Fork 1.4k
allow dictionary image only and test endianness #1669
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
9 commits
Select commit
Hold shift + click to select a range
6559460
allow dictionary image only and test endianness
rijobro 34ebc8a
switch endianness of meta data
rijobro e0a395c
fix test_load_image
rijobro 67b5feb
Merge branch 'master' into nifti_endianness
rijobro dcb52bd
type checking
rijobro e5a14a6
switch order
rijobro ef01a1b
add docstring
rijobro d044def
Merge branch 'master' into nifti_endianness
rijobro 3bcb71d
autofix
rijobro 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
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,48 @@ | ||
| import tempfile | ||
| import unittest | ||
| from typing import TYPE_CHECKING, List, Tuple | ||
| from unittest.case import skipUnless | ||
|
|
||
| import numpy as np | ||
| from parameterized import parameterized | ||
|
|
||
| from monai.data import DataLoader, Dataset, create_test_image_2d | ||
| from monai.transforms import LoadImage, LoadImaged | ||
| from monai.utils.module import optional_import | ||
|
|
||
| if TYPE_CHECKING: | ||
| import nibabel as nib | ||
|
|
||
| has_nib = True | ||
| else: | ||
| nib, has_nib = optional_import("nibabel") | ||
|
|
||
| TESTS: List[Tuple] = [] | ||
| for endianness in ["<", ">"]: | ||
| for use_array in [True, False]: | ||
| for image_only in [True, False]: | ||
| TESTS.append((endianness, use_array, image_only)) | ||
|
|
||
|
|
||
| class TestNiftiEndianness(unittest.TestCase): | ||
| def setUp(self): | ||
| self.im, _ = create_test_image_2d(100, 100) | ||
| self.fname = tempfile.NamedTemporaryFile(suffix=".nii.gz").name | ||
|
|
||
| @parameterized.expand(TESTS) | ||
| @skipUnless(has_nib, "Requires NiBabel") | ||
| def test_endianness(self, endianness, use_array, image_only): | ||
|
|
||
| hdr = nib.Nifti1Header(endianness=endianness) | ||
| nii = nib.Nifti1Image(self.im, np.eye(4), header=hdr) | ||
| nib.save(nii, self.fname) | ||
|
|
||
| data = [self.fname] if use_array else [{"image": self.fname}] | ||
| tr = LoadImage(image_only=image_only) if use_array else LoadImaged("image", image_only=image_only) | ||
| check_ds = Dataset(data, tr) | ||
| check_loader = DataLoader(check_ds, batch_size=1) | ||
| _ = next(iter(check_loader)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.