使用imwrite opencv python函数写入同一图像后更改像素值 [英] Changing of pixel values after writing the same image using imwrite opencv python function

查看:119
本文介绍了使用imwrite opencv python函数写入同一图像后更改像素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import cv2
import numpy as np
im=cv2.imread('test.jpg')
cv2.imwrite('result.jpg',im)

此处test.jpg的大小为19 KB,result.jpg的大小为41 KB,即使它们是相同的图像.

Here test.jpg have size 19 KB and result.jpg have 41 KB even though they are same images.

我观察到这两个图像的像素值有变化.

I observed that there is change in the pixel values of these two images.

如何预防这种情况?

推荐答案

在任何库或工具中重写或保存"图像将始终创建一个新文件或新像素值".发生这种情况是因为正在处理图像以某种质量进行保存.保存的图像质量和大小取决于执行保存的库.因此,需要提供默认值,深度,压缩等.

Re-writing or 'saving' an image in any library or tool will always create a new file or 'new pixel values'. This happens because the image is being processed for saving at a certain quality. The saved image quality and size depends on the library doing the save. So default values, depth, compression, etc. need to be provided.

如果您只想在新文件中创建图像的副本,则可以直接通过 sys 复制该文件,也可以二进制读取整个文件并将其写入新文件-不使用任何文件图像处理库.

If you just want to create a copy of the image in a new file, either copy the file directly via sys or binary read the whole file and write it to a new one - without using any image processing libs.

这篇关于使用imwrite opencv python函数写入同一图像后更改像素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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