PNG 裁剪会增加文件大小

问题描述 投票:0回答:1

我有一组 PNG 240x240px 图像(约 1Gb 的图像)用于训练分类算法,我需要从这些图像中裁剪底部 26px(结果为 240x214px),其中包含一些我不想要的数字和日期最终图像集。

我从一个名为 Pillow 的 python 库开始,但很快意识到在读取、裁剪和重新保存 PNG 图像后,文件大小增加了约 5 倍(约 5Gb 的图像)。

我想我知道它不会影响CNN的结果,但主要是训练它所花费的时间,但我仍然想知道是否有更好的压缩方法或任何其他方法来保持原始文件大小。

我将附上一张处理前(11Kb)和处理后(74Kb)的图像作为示例。

这是我用来裁剪图像的代码:

from os import listdir
from PIL import Image

def cropp_images_in_folder(from_folder, to_folder):
    for image in listdir(from_folder):
        if image.endswith(".png"):
            full_path = from_folder + image
            im = Image.open(full_path)
            im1 = im.crop((0, 0, 240, 214))
            full_path = to_folder + image
            im1.save(full_path, optimize=True, compress_level = 9)
            i += 1
image-processing conv-neural-network python-imaging-library compression png
1个回答
0
投票

我有一组 PNG 240x240px 图像...

第一张图片不是 PNG。是 JPEG。第二张图片是PNG。如果您想要第二张图像的尺寸更具可比性,请将其也压缩为 JPEG。

© www.soinside.com 2019 - 2024. All rights reserved.