Skip to content
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

Improve performance of label2rgb #839

Open
wants to merge 2 commits into
base: branch-25.04
Choose a base branch
from

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Feb 17, 2025

This MR substantially improves the performance of label2rgb by using custom elementwise kernels.

A few fixes in the benchmark scripts were also made

  • use int32 dtype for the labels during benchmarks
  • Fix label2rgb benchmark bug where 3rd dimension was truncated.
  • Use n-d blobs image as a more realistic label image.

Accelerations vs skimage before vs. after this change (when image is used it has dtype=np.float32)

shape (no image, mode='overlay') previous new
(512, 512) 7.6 27.0
(3840, 2160) 25.4 35.9
(192, 192, 192) 76.1 365.6
shape (with image, mode='overlay') previous new
(512, 512) 51.7 110.6
(3840, 2160) 262.5 309.8
(192, 192, 192) 693.1 1334.7
shape (with image, mode='avg') previous new
(512, 512) 2.5 322.5
(3840, 2160) 66.7 1330.6
(192, 192, 192) 63.7 1374.0

@grlee77 grlee77 added improvement Improves an existing functionality non-breaking Introduces a non-breaking change performance Performance improvement labels Feb 17, 2025
@grlee77 grlee77 added this to the v25.04.00 milestone Feb 17, 2025
@grlee77 grlee77 requested a review from a team as a code owner February 17, 2025 18:52
@grlee77 grlee77 force-pushed the label2rgb-performance branch from aaad6f2 to 3cc00cb Compare February 17, 2025 21:05
also address various issues in the benchmarks
* use int32 dtype for the labels during benchmarks
* Fix label2rgb benchmark bug where 3rd dimension was truncated.
* Use n-d blobs image as a more realistic label image.
@grlee77 grlee77 force-pushed the label2rgb-performance branch from 3cc00cb to 9df629a Compare February 17, 2025 21:05
Copy link
Contributor

@gigony gigony left a comment

Choose a reason for hiding this comment

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

Thanks @grlee77 for improving the label2rgb performance!
It looks good to me but I found a typo which may lead to the incorrect result.

if (label == bg_label) {
out[3*i] = bg_color[0];
out[3*i + 1] = bg_color[1];
out[3*i + 1] = bg_color[2];
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this original index is correct or not. I guess it should be:

Suggested change
out[3*i + 1] = bg_color[2];
out[3*i + 2] = bg_color[2];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change performance Performance improvement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants