Skip to content

Image Geometry get_slice returns IG with offset centre - #2235

Open
lauramurgatroyd wants to merge 14 commits into
masterfrom
image_geom_get_slice
Open

Image Geometry get_slice returns IG with offset centre#2235
lauramurgatroyd wants to merge 14 commits into
masterfrom
image_geom_get_slice

Conversation

@lauramurgatroyd

@lauramurgatroyd lauramurgatroyd commented Oct 29, 2025

Copy link
Copy Markdown
Member

Description

Closes #2217

  • Adds get_centre_slice method to ImageData, ImageGeometry, AcquisitionGeometry
  • Allows passing vertical='centre' to ImageGeometry.get_slice
  • Sets center_x, center_y, center_z appropriately for ImageGeometry returned by get_slice

Example Usage

Contribution Notes

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

Changes

Testing you performed

Please add any demo scripts to https://github.com/TomographicImaging/CIL-Demos/tree/main/misc

Added unit tests for:

  • Image Geometry get_slice
  • New get_centre_slice methods

Related issues/links

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers

@lauramurgatroyd
lauramurgatroyd marked this pull request as ready for review October 30, 2025 11:57

@hrobarts hrobarts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Laura, this looks really useful. Just a couple of questions.

Comment thread Wrappers/Python/cil/framework/image_data.py
Comment thread Wrappers/Python/cil/framework/image_geometry.py Outdated
Comment thread Wrappers/Python/test/test_DataContainer.py
Comment thread Wrappers/Python/cil/framework/image_geometry.py Outdated
Signed-off-by: Laura Murgatroyd <60604372+lauramurgatroyd@users.noreply.github.com>
Signed-off-by: Laura Murgatroyd <60604372+lauramurgatroyd@users.noreply.github.com>
@gfardell

Copy link
Copy Markdown
Member

Can we have a meeting about this, maybe we could discuss it in a dev meeting. I remember lots of discussions about axis lengths or 0 vs 1 and what it meant, but I don't remember what we landed on or what the implications were.

Comment on lines +212 to +215
if vertical == 0:
warnings.warn("Slicing vertical at index 0 results in a geometry \
offset along the vertical axis. If you do not require an offset ImageGeometry, set vertical='centre",
UserWarning)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gfardell - this is what we decided on previously - to raise a warning if they set vertical=0


if vertical is not None:
geometry_new.voxel_num_z = 0
geometry_new.voxel_num_z = 1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this does not mean the shape is 1 in this dimension:

for i, x in enumerate(shape_default):
if x == 0 or x==1:
try:
labels.remove(labels_default[i])
except ValueError:
pass #if not in custom list carry on
return tuple(labels)

Signed-off-by: Laura Murgatroyd <60604372+lauramurgatroyd@users.noreply.github.com>
def get_slice(self,channel=None, vertical=None, horizontal_x=None, horizontal_y=None):
'''
Returns a new ImageGeometry of a single slice of in the requested direction.
Returns a new ImageGeometry of a single slice in the requested direction.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear where index 0 sits

def get_slice(self,channel=None, vertical=None, horizontal_x=None, horizontal_y=None):
'''
Returns a new ImageGeometry of a single slice of in the requested direction.
Returns a new ImageGeometry of a single slice in the requested direction.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make really clear, single 2D slice in 3D space with offset calculated from where it was in 3D original object

Puts one slice at location where it was requested
offset is height of slice from centre

Add example - if used with vertical this is what you'd get

@lauramurgatroyd

Copy link
Copy Markdown
Member Author

After discussion with @gfardell and @paskino today, updating ImageGeometry and ImageData significantly.

  • ImageData and ImageGeometry should always be 3D, so always have at least size 1 on vertical, horizontal_x, horizontal_y
    • This means number of voxels can't be 0 on any of these axes, and should default to 1.
    • Need check on if all dims > 1 have labels, if not add these in. Prepend dimension if needed.
    • Consider having a 'None' dimension for e.g. channels or true 2D slice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

ImageGeometry's get_slice ignores input parameters

3 participants