-
Notifications
You must be signed in to change notification settings - Fork 223
Add PyBuffer interface to Image (PEP 688) and numpy array conversion #2447
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
Add PyBuffer interface to Image (PEP 688) and numpy array conversion #2447
Conversation
|
@dave3d Is there a way to tell the spell checker to ignore a whole file? In the pre-commit config or else where? |
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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 )