-
Notifications
You must be signed in to change notification settings - Fork 60
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
Binary morphology: omit weights array when possible #517
Binary morphology: omit weights array when possible #517
Conversation
also use tuples when possible in footprint decompositions
…e footprint e.g. out = binary_erosion(img2d, footprint=(3, 5))
make sure grayscale morphology also works for tuple-based footprints
…y if dtype is specified if dtype is None: square, rectangle and cube can return a tuple instead default to dtype=None on these for performance
98f7c16
to
abfc4d8
Compare
Benchmark resultsAcceleration here is the ratio of the runtime when passing a boolean array of These are worse case accelerations as they assume the footprint had already been created and don't include the initial overhead of allocating the footprint on the GPU. Acceleration factors run from ~3x for small images approaching 1x as the image size becomes larger.
|
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.
Thanks @grlee77 ! Looks good to me!
@@ -144,19 +167,30 @@ def square(width, dtype=cp.uint8, *, decomposition=None): | |||
The 'sequence' decomposition mode only supports odd valued `width`. If | |||
`width` is even, the sequence used will be identical to the 'separable' | |||
mode. | |||
|
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.
unnecessary blank line?
rerun tests |
@gigony, test failures in unrelated isotropic morphology functions have been fixed. I added checks to enforce properties of the provided output. |
/merge |
This is a follow-up to #485 allowing the overhead of creating a weights array of uniform values to be omitted when possible for all binary morphology operators. This gives a large performance benefit for small footprints (and small images) with the benefit becoming minimal for large footprint size.
As currently implemented, a shape tuple can be passed to
structure
to indicate the equivalent of an array of ones of that shape. This is a deviation from SciPy's API which does not currently allow this. I am not positive if this is the best API choice or if it might be better to instead add asize
keyword-only argument like the grayscale morphology functions currently have.The footprint generation methods
square
,rectangle
,cube
etc. use this new tuple format when possible to reduce overhead.I will post benchmarks below.