OpenCV - imread(),imwrite()增加了png的大小? [英] OpenCV - imread(), imwrite() increases the size of png?

查看:1658
本文介绍了OpenCV - imread(),imwrite()增加了png的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对文件进行一些简单的操作,我开始打开并保存文件(我使用Python)

I wanted to try out some simple operations on files and I started with opening and saving files (I use Python)

image = cv2.imread("image.png")
cv2.imwrite("image_processed.png", image)

在此操作之后,来自33kB的原始图像转换为相同的144kB图像。

After this operation my original image from 33kB transforms into the same looking 144kB image.

我尝试过这样的事情: http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

I have tried doing something like this : http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imwrite#imwrite

    params = list()
    params.append(cv.CV_IMWRITE_PNG_COMPRESSION)
    params.append(8)

    image = cv2.imread("image.png")
    cv2.imwrite("image_processed.png",image,params)

但这并没有太大变化(尺寸减少到132kB)

But this does not change much ( size decreased to 132kB )

这是我正在使用的图像:

This is the image which I am working with:

推荐答案

像GIMP这样的png编写者编写的压缩PNG比opencv使用的标准libpng要好得多。您还可以使用Imagemagick再次打开并保存图像,并查看它与(与OpenCV相比)产生的差异。

Some png writers like GIMP write much better compressed PNGs than standard libpng, which is used by opencv. You can also open and save the image again with Imagemagick, and see what difference that makes (as compared to OpenCV).

甚至有专门的软件试图更好地重新制作 - 压缩PNG,比如pngcrush。

There is even specialized software that tries to better re-compress PNGs, like pngcrush.

你能提供有问题的图片吗?关于文件大小优化,我想玩它。

Can you provide the image in question? I would like to play with it, regarding file size optimization.

这篇关于OpenCV - imread(),imwrite()增加了png的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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