OpenCV写入为jpeg图像提供冲洗结果 [英] OpenCV imwrite gives washed-out result for jpeg images

查看:86
本文介绍了OpenCV写入为jpeg图像提供冲洗结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是OpenCV 3.0,每当我读取图像并将其写回时,结果都是被冲洗掉的图像.

I am using OpenCV 3.0 and whenever I read an image and write it back the result is a washed-out image.

代码:

cv::Mat img = cv::imread("dir/frogImage.jpg",-1);
cv::imwrite("dir/result.jpg",img);

有人知道是什么原因造成的吗?

Does anyone know whats causing this?

原件:

结果:

推荐答案

您可以尝试增加压缩质量参数,如

You can try to increase the compression quality parameter as shown in OpenCV Documentation of cv::imwrite :

cv::Mat img = cv::imread("dir/frogImage.jpg",-1);

std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);

cv::imwrite("dir/result.jpg",img, compression_params);

不手动指定压缩质量,将应用95%的质量.

Without specifying the compression quality manually, quality of 95% will be applied.

但是1.您不知道原始图像具有什么jpeg压缩质量(因此可能会增加图像大小),并且2.它仍会(afaik)引入其他较小的伪像,因为毕竟这是有损的压缩方法.

but 1. you don't know what jpeg compression quality your original image had (so maybe you might increase the image size) and 2. it will (afaik) still introduce additional minor artifacts, because after all it is a lossy compression method.

更新,您的问题似乎不是由于压缩伪像,而是由于图像的颜色为Adobe RGB 1998. OpenCV照原样解释颜色值,但是应该缩放颜色值以适合实际" RGB颜色空间.浏览器和某些图像查看器确实正确应用了颜色格式,而其他浏览器则没有(例如irfanView).我使用GIMP进行了验证.使用GIMP,您可以决定在启动时如何通过格式解释颜色值,以获得所需的图像或冲洗掉"的图像. OpenCV绝对不关心此类事情,因为它不是照片编辑库,因此无论是阅读还是书写,都不会处理颜色格式.

UPDATE your problem seems to be not because of compression artifacts but because of an image with Adobe RGB 1998 color format. OpenCV interprets the color values as they are, but instead it should scale the color values to fit the "real" RGB color space. Browser and some image viewers do apply the color format correctly, while others don't (e.g. irfanView). I used GIMP to verify. Using GIMP you can decide on startup how to interpret the color values by format, either getting your desired or your "washed out" image. OpenCV definitely doesn't care about such things, since it's not a photo editing library, so neither on reading nor on writing, color format will be handled.

这篇关于OpenCV写入为jpeg图像提供冲洗结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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