简体   繁体   中英

Is it possible automate to changing all colors in an image to random colors?

在此处输入图像描述

I'm trying to come up with a new image augmentation that changes colors like above automatically, but to everything not just the flower. The above is a photoshop example but I'd like to automatically switch all colors in the image to a different random color. Is this possible to create a function for this? There are augmentations like random convolution and random jitter, but those aren't quite what I want. I'd like to keep the saturations and values the same just change the color.

You can add a random 0 to 255 shift to each channel in BGR and take modulo 256.

In python it would look like:

shift = numpy.random.randint(256, size=(1,1,3))
color_shifted_img = img + shift
color_shifted_img = numpy.mod(color_shifted_img, 256)

输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM