Group Abstract Group Abstract

Message Boards Message Boards

2
|
10K Views
|
2 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Faster ways to hue shift an RGB? OpenCV in Python still 3x faster

testImage = ExampleData[{"TestImage", "Mandrill"}]

This method is based on example in docs and is super slow

RepeatedTiming@
 ColorConvert[
  ImageApply[Function[{h, s, b}, {Mod[h + .5, 1], s, b}] @@ # &, 
   ColorConvert[testImage, "HSB"]], "RGB"]

This method is my old school data manipulation and is twice as fast

RepeatedTiming@
 ColorConvert[
  Image[MapAt[Function[{h}, Mod[h + .5, 1]], 
    ImageData@ColorConvert[testImage, "HSB"], {All, All, 1}], 
   ColorSpace -> "HSB"], "RGB"]

And this method seems to be as fast as I can get the system to perform, which is 20x faster than the example from the docs

RepeatedTiming@
 ColorConvert[
  ImageApply[
   Function[{rgb}, MapAt[Function[{p}, Mod[p + .5, 1]], rgb, 1]], 
   ColorConvert[testImage, "HSB"]], "RGB"]

And even still OpenCV in Python is running 3x faster than that. I am running on hundreds of thousands of images so every little boost helps. I think CUDAImageApply does not help since I would need to load and unload each image onto GPU unless I am missing something?

Any hints/ideas/suggestions?

POSTED BY: Kyle Keane
2 Replies
POSTED BY: Piotr Wendykier

Bravo, this was really clever, thank you!

POSTED BY: Kyle Keane
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard