-
Notifications
You must be signed in to change notification settings - Fork 66
Image Geometry get_slice returns IG with offset centre #2235
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
Open
lauramurgatroyd
wants to merge
13
commits into
master
Choose a base branch
from
image_geom_get_slice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ba301fb
fix image_geom_get_slice
lauramurgatroyd 962d2af
Fix get_slice tests
lauramurgatroyd 4b64825
Image geometry slice is now 2D
lauramurgatroyd be94d8e
Add new unit tests
lauramurgatroyd c1363c8
Test voxel size z is maintained
lauramurgatroyd 5d861ba
Add tests for getting centre slices
lauramurgatroyd 5af89fe
Merge branch 'master' into image_geom_get_slice
lauramurgatroyd 06d92df
Fix unit test
lauramurgatroyd 1935528
Merge branch 'image_geom_get_slice' of https://github.com/Tomographic…
lauramurgatroyd 5d393a4
Update CHANGELOG with new features and bug fixes
lauramurgatroyd 991384c
Remove centre option on horizontal axes
lauramurgatroyd a0873f8
Merge branch 'master' into image_geom_get_slice
lauramurgatroyd 8ad816b
Merge branch 'master' into image_geom_get_slice
lauramurgatroyd 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
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,109 @@ | ||
| # Copyright 2025 United Kingdom Research and Innovation | ||
| # Copyright 2025 The University of Manchester | ||
| # | ||
| # 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. | ||
| # | ||
| # Authors: | ||
| # CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt | ||
|
|
||
| import unittest | ||
| from utils import initialise_tests | ||
| from cil.framework import ImageGeometry | ||
| from cil.framework.labels import ImageDimension | ||
|
|
||
| initialise_tests() | ||
|
|
||
|
|
||
| class TestImageGeometry(unittest.TestCase): | ||
| def setUp(self): | ||
| self.ig = ImageGeometry(2,3,4,channels=5) | ||
|
|
||
| # get_slice tests --------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| def test_get_slice_vertical(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["CHANNEL"], ImageDimension["HORIZONTAL_Y"], | ||
| ImageDimension["VERTICAL"]] | ||
| ig = self.ig.copy() | ||
| ig.set_labels(non_default_dimension_labels) | ||
| ig.voxel_size_z = 5.5 | ||
| sub = ig.get_slice(vertical = 1) | ||
| self.assertTrue( sub.shape == (2,5,3)) | ||
| self.assertEqual(sub.voxel_size_z,5.5) | ||
| self.assertEqual(sub.center_x,0) | ||
| self.assertEqual(sub.center_y,0) | ||
| self.assertEqual(sub.center_z,-0.5*sub.voxel_size_z) | ||
|
|
||
| def test_get_slice_vertical_centre(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["CHANNEL"], ImageDimension["HORIZONTAL_Y"], | ||
| ImageDimension["VERTICAL"]] | ||
| self.ig.set_labels(non_default_dimension_labels) | ||
| sub = self.ig.get_slice(vertical = 'centre') | ||
| self.assertTrue( sub.shape == (2,5,3)) | ||
| self.assertEqual(sub.center_x,0) | ||
| self.assertEqual(sub.center_y,0) | ||
| self.assertEqual(sub.center_z,0) | ||
|
|
||
|
|
||
| def test_get_slice_horizontal_x(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["CHANNEL"], ImageDimension["HORIZONTAL_Y"], | ||
| ImageDimension["VERTICAL"]] | ||
| self.ig.set_labels(non_default_dimension_labels) | ||
| sub = self.ig.get_slice(horizontal_x = 1) | ||
| self.assertTrue(sub.shape == (5,3,4)) | ||
| self.assertEqual(sub.center_x,0.5) | ||
| self.assertEqual(sub.center_y,0) | ||
| self.assertEqual(sub.center_z,0) | ||
|
|
||
|
|
||
| def test_get_slice_channel(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["CHANNEL"], ImageDimension["HORIZONTAL_Y"], | ||
| ImageDimension["VERTICAL"]] | ||
| self.ig.set_labels(non_default_dimension_labels) | ||
| sub = self.ig.get_slice(channel = 1) | ||
| self.assertTrue(sub.shape == (2,3,4)) | ||
| self.assertTrue(sub.channels == 1) | ||
|
|
||
| def test_get_slice_channel_centre(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["CHANNEL"], ImageDimension["HORIZONTAL_Y"], | ||
| ImageDimension["VERTICAL"]] | ||
| self.ig.set_labels(non_default_dimension_labels) | ||
| sub = self.ig.get_slice(channel = 'centre') | ||
| self.assertTrue(sub.shape == (2,3,4)) | ||
| self.assertTrue(sub.channels == 1) | ||
|
|
||
| def test_get_slice_horizontal_y(self): | ||
| non_default_dimension_labels = [ImageDimension["HORIZONTAL_X"], ImageDimension["HORIZONTAL_Y"]] | ||
| self.ig.set_labels(non_default_dimension_labels) | ||
| sub = self.ig.get_slice(horizontal_y = 0) | ||
| self.assertTrue( sub.shape == (2,)) | ||
| self.assertEqual(sub.center_x,0) | ||
| self.assertEqual(sub.center_y,-1) | ||
| self.assertEqual(sub.center_z,0) | ||
|
|
||
| def test_get_slice_horizontal_x_and_horizontal_y(self): | ||
| sub = self.ig.get_slice(horizontal_x=0,horizontal_y=0) | ||
| self.assertTrue( sub.shape == (5,4)) | ||
|
|
||
| # test get_centre_slice --------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| def test_get_centre_slice(self): | ||
| sub = self.ig.get_centre_slice() | ||
| sub2 = self.ig.get_slice(vertical='centre') | ||
| self.assertTrue( sub == sub2) | ||
|
|
||
| # ------------------------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| def test_shape_change_with_new_labels(self): | ||
| new_dimension_labels = [ImageDimension["HORIZONTAL_Y"], ImageDimension["CHANNEL"], ImageDimension["VERTICAL"], ImageDimension["HORIZONTAL_X"]] | ||
| self.ig.set_labels(new_dimension_labels) | ||
| self.assertTrue( self.ig.shape == (3,5,4,2)) |
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
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.