简体   繁体   中英

Python opencv/cv2 mis-colorations

Example image : 范例图片

I'm working on a project in Python with OpenCV where I need to fade the colors of an image a little to make it darker. Things have been going ok so far except that I'm getting weird mis-colorations in the resulting image where large areas are either white or purple or similar. See the attached example. I can't find any explanation for this even after extensive Googling. Any ideas what might be causing this?

My code looks like this:

poster = stbt.load_image("test1.png")
b, g, r = cv2.split(poster)
val = 40
b -= val
g -= val
r -= val
poster = cv2.merge((b, g, r))
cv2.imshow("frame2", poster)
cv2.waitKey(0)
cv2.destroyAllWindows()

Thanks everyone! I've tried a lot of things including the suggestions above. I did manage to get rid of the miscolorations but still couldn't get quite the result I wanted. However I found this https://pillow.readthedocs.io/en/3.0.x/index.html which looks like it should be able to do the trick for me.

Edit: I tested the above solution and it worked fine :). See example below:

from PIL import Image, ImageEnhance

img = Image.open("dev/poster.png")
br = ImageEnhance.Brightness(img)
img = br.enhance(0.7)
img.show("")

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