当我在Python中加载图像后,当我保存图像后,为什么文件大小有差异

发布于 2025-01-29 04:03:11 字数 484 浏览 2 评论 0原文

我在Python中加载了PNG图像,并使用Python中的CV2保存了后,但是我得到的文件大小差异很大。有没有办法将压缩比作为输入?

print('input:',os.path.getsize("colorful_image.png"))
img = cv2.imread("colorful_image.png")
cv2.imwrite("output.png",img,[int(cv2.IMWRITE_PNG_COMPRESSION),9])
print('output:',os.path.getsize('output.png'))
print('ratio:',os.path.getsize('output.png')/os.path.getsize("colorful_image.png"))

输出如下

input: 239868
output: 3475548
ratio: 14.489419180549302
 

I loaded a PNG image in python and saved it back using cv2 in python, but I am getting a huge file size difference. Is there a way to get compression ratio as that of input?

print('input:',os.path.getsize("colorful_image.png"))
img = cv2.imread("colorful_image.png")
cv2.imwrite("output.png",img,[int(cv2.IMWRITE_PNG_COMPRESSION),9])
print('output:',os.path.getsize('output.png'))
print('ratio:',os.path.getsize('output.png')/os.path.getsize("colorful_image.png"))

The output is as follows

input: 239868
output: 3475548
ratio: 14.489419180549302
 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2025-02-05 04:03:11

通过这篇文章查看。 scipy.misc.imsave正确保存图像作为8位图像。 opencv-imread(),imRead(),imregrite()增加png? /a>

check it out by this post. scipy.misc.imsave save images correctly as an 8-bit image. OpenCV - imread(), imwrite() increases the size of png?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文