OpenCV imrite为jpeg图像提供了褪色结果 [英] OpenCV imrite gives washed-out result for jpeg images

查看:298
本文介绍了OpenCV imrite为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?

原文:

结果:

推荐答案

您可以尝试增加压缩质量参数,如 cv :: imwrite的OpenCV文档

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.

UPDATE 你的问题似乎不是因为压缩工件而是因为带有<$的图像c $ c> Adob​​e 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 imrite为jpeg图像提供了褪色结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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