Add PyBuffer interface to Image (PEP 688) and numpy array conversion#2447
Merged
blowekamp merged 4 commits intoSimpleITK:mainfrom Nov 20, 2025
Merged
Add PyBuffer interface to Image (PEP 688) and numpy array conversion#2447blowekamp merged 4 commits intoSimpleITK:mainfrom
blowekamp merged 4 commits intoSimpleITK:mainfrom
Conversation
Member
Author
|
@dave3d Is there a way to tell the spell checker to ignore a whole file? In the pre-commit config or else where? |
Member
You could disable spell checking within the file by putting in the comment: "// spell-check-disable" https://github.com/SimpleITK/CommentSpellCheck?tab=readme-ov-file#disabling-spell-checking or maybe adding the file name to the "exclude" line in the YAML file. |
d8184b5 to
0db7604
Compare
zivy
approved these changes
Nov 20, 2025
Member
zivy
left a comment
There was a problem hiding this comment.
So Pythonic and makes the usage of views safer for users. Very nice work!
Some trivial spelling that can be ignored.
The ImageBuffer class maintains a reference the the python Image instance, which solves the dangling pointer for memory buffers with the prior _GetMemoryViewFromImage method.
Allow for implicit view as numpy arrays as read-only buffers which maintain a reference to the Python Image object. Implement PEP 688 for Python >= 3.12, by adding the __buffer__ method.
Useful functions to determine the class of pixel type. This is current in a private module and may be implemented C++ in the future. fix up for pixel types
The function was private and can be removed without deprecation.
0db7604 to
2b99ad4
Compare
7 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Enables view and conversions to numpy arrays with the following:
References to the Python Image object are maintained.
COMPATIBILITY:
Images of vector pixel type with only 1 component now return memory views and arrays of n+1 dimensions. ( Previously the 1 size component dimension was dropped )