颜色变暗:opencv cv2.imread cv2.imwrite [英] Color gets dull: opencv cv2.imread cv2.imwrite

查看:88
本文介绍了颜色变暗:opencv cv2.imread cv2.imwrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencv模块读取和写入图像.这是代码,下面是我正在读取的图像,第二个图像是使用cv2.imwrite()将其保存在磁盘上之后.

I am using opencv module to read and write the image. here is the code and below is the image i am reading and second image is after saving it on disk using cv2.imwrite().

import cv2

img = cv2.imread('originalImage.jpg')
cv2.imwrite('test.jpg',img)

在第二张图像中色彩暗淡明显可见.有没有解决此问题的方法,或者我缺少某种设置参数..?

It is significantly visible that colors are dull in second image. Is there any workaround to this problem or I am missing on some sort of setting parameters..?

推荐答案

我对有关ICC配置文件的@mark问题做了一些研究.我想出了一种在python PIL模块中处理此问题的方法.这是对我有用的代码.我还学会了使用PNG文件格式而不是JPEG进行无损转换.

I have done a bit of research on the point @mark raised about ICC profile. I have figured out a way to handle this in python PIL module. here is the code that worked for me. I have also learned to use PNG file format rather JPEG to do lossless conversion.

import Image
img = Image.open('originalImage.jpg')
img.save('test.jpg',icc_profile=img.info.get('icc_profile'))

我希望这也会对其他人有所帮助.

I hope this will help others as well.

这篇关于颜色变暗:opencv cv2.imread cv2.imwrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆