如何确定PNG24转换为PNG8时是无损的?

发布于 2024-10-10 04:50:45 字数 296 浏览 0 评论 0原文

嘿,我正在使用一个名为 pngquant 的程序将 24 位 PNG 转换为 8 位 PNG。一切似乎都工作正常,我没有注意到图标和其他不包含太多颜色的图像有任何质量损失。现在,当我向它提供一张具有无数种颜色的 PNG 照片时,它会生成一个 PNG8,我可以看到一些质量损失。

我想以编程方式确定质量损失。我想知道将 PNG24 转换为 PNG8 是否安全。类似于webpagetest.org 所做的——他们告诉您,如果转换为PNG8,该特定图像的尺寸会更小,并且不会降低质量。

有什么想法吗?

谢谢。

Hey, i'm using a program called pngquant to convert 24 bit PNGs to 8-bit PNGs. Everything seems to work fine, and I don't notice any loss of quality for icons and other images that don't contain too much colors. Now when I feed it a PNG photo with zillions of colours, it produces a PNG8 where I can see some quality loss.

I'd like to determine that quality loss programmatically. I'd like to know when converting a PNG24 to PNG8 is safe or not. Sort of what webpagetest.org does -- they tell you that this specific image will be smaller in size if converted to PNG8 and will not loose quality.

Any ideas?

Thanks.

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

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

发布评论

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

评论(3

他夏了夏天 2024-10-17 04:50:45

这听起来像是一个完整参考图像质量评估问题。

解决此问题的最简单方法是尝试计算 PNG24 和PNG8 图像。这是两个图像之间差异的度量。 PSNR 越高,图像差异越小。使用颜色量化软件后,检查 PSNR 是否高于某个阈值(您必须凭经验确定),如果是,则量化是“安全的”。

PSNR 有其缺点,即它并不总是符合人类视觉系统的工作方式(例如,它忽略了空间和对比度掩蔽现象)。另一个指标 SSIM 试图解决这个问题,但计算起来稍微困难一些(不过,这里有一个 OpenCV 实现)。在我上面描述的阈值方法中,您可以使用 SSIM 代替 PSNR。

这是另一个线程你可能会发现有用。

This sounds like a full-reference image quality assessment problem.

The simplest way to approach this is to try computing the PSNR between the PNG24 and PNG8 images. This is a measure of the difference between the two images. The higher the PSNR, the less different the images are. After using your color quantization software, check if the PSNR is above some threshold (you'll have to determine that empirically), and if it is, then the quantization was "safe".

PSNR has its down sides, namely the fact that it doesn't always correspond to the way the human visual system works (for example, it neglects the phenomenon of spatial and contrast masking). Another metric, SSIM, attempts to take care of that problem, but is slightly more difficult to compute (here is an OpenCV implementation, though). You can use SSIM instead of PSNR in the thresholding approach I described above.

Here's another thread which you might find useful.

夜巴黎 2024-10-17 04:50:45

很简单。如果您从 PNG24 转换为 PNG8 的图像颜色超过 256 种,质量就会下降。我错过了什么吗?

Quite simple. If the image you are converting from PNG24 to PNG8 has more thant 256 colors, you gonna loose quality. Do I missed something?

呆萌少年 2024-10-17 04:50:45

为了开发 pngquant,我使用 我自己的 SSIM 工具,因为基于 OpenCV 的工具似乎不支持伽玛校正和阿尔法通道均正确。

当您运行 pngquant -v 时,它将输出作为 MSE=n 引入的误差量(n 是均方误差 - 0 是完美质量) 。

最新版本具有 --quality 设置,可让您设置所需的最低质量。如果无法实现,则不会保存文件。

For development of pngquant I use my own SSIM tool, since the OpenCV-based one didn't seem to support gamma correction nor alpha channel properly.

When you run pngquant -v it will output amount of error introduced as MSE=n (n is mean square error — 0 is perfect quality).

The latest version has --quality setting which lets you set minimum required quality. If it can't achieve it, it won't save the file.

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