能否在不损失质量的情况下旋转 JPEG 压缩图像?

发布于 2024-07-13 12:43:12 字数 219 浏览 10 评论 0原文

JPEG 是一种有损压缩方案,因此解压缩-操作-再压缩通常会进一步降低每个步骤的图像质量。 是否可以旋转 JPEG 图像而不会造成进一步的损失? 根据我对 JPEG 算法的了解,天真的似乎可以通过一点努力来避免进一步的损失。 哪些常见的图像处理程序(例如 GIMP、Paint Shop Pro、Windows Photo Gallery)和图形库在执行旋转时会导致质量损失,哪些不会?

JPEG is a lossy compression scheme, so decompression-manipulation-recompression normally reduces the image quality further for each step. Is it possible to rotate a JPEG image without incurring further loss? From what little I know of the JPEG algorithm, it naively seems possible to avoid further loss with a bit of effort. Which common image manipulation programs (e.g. GIMP, Paint Shop Pro, Windows Photo Gallery) and graphic libraries cause quality loss when performing a rotation and which don't?

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

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

发布评论

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

评论(10

奢欲 2024-07-20 12:43:12

有一个名为 jpegtran 的程序

jpegtran – 用于在不同 JPEG 格式之间进行无损转码的实用程序。

要无损旋转图像,您可以执行以下操作:

$ jpegtran -rotate 180 -perfect -outfile rotated.jpg origin.jpg

这里是提供基于 JPEG 无损旋转功能的应用程序列表关于 IJG 代码

There is a program named jpegtran

jpegtran – a utility for lossless transcoding between different JPEG formats.

To rotate the image losslessly, you can do the following:

$ jpegtran -rotate 180 -perfect -outfile rotated.jpg origin.jpg

And Here is a list of applications which provide the JPEG lossless rotation feature based on the IJG code

笑着哭最痛 2024-07-20 12:43:12

是的,在某些情况下是可能的:图像进行 90 度旋转和翻转。 JPEG 算法的核心(有损部分)涉及将图像分解为 8x8 像素块,执行 对块进行离散余弦变换,然后量化结果。 除此之外还有一些颜色空间转换和块的无损压缩。

旋转或翻转 8x8 块将给出具有相同基本系数的 DCT,但可能会转置和/或根据变换进行一些符号更改。 因此,无损旋转或翻转图像的基本步骤包括:

  1. 解压缩并提取块
  2. 转置和/或符号翻转 每个块的 DCT 系数
  3. 将块重新排列为新顺序(否则 8x8 块将被旋转,但仍处于老地方)
  4. 用无损压缩步骤重新压缩它。

Yes, it is possible for certain cases: 90-degree rotations and flips on images. The heart of the JPEG algorithm -- the lossy part -- involves breaking the image into 8x8 pixel blocks, performing a discrete cosine transform on the block and then quantizing the result. There's also some color space conversion and lossless compression of the blocks on top of this.

Rotating or flipping an 8x8 block will give a DCT with the same basic coefficients, but possibly transposed and/or with some sign changes depending on the transformation. So the basic steps to rotate or flip an image losslessly would involve:

  1. Decompress and extract the blocks
  2. Transpose and/or sign flip the DCT coefficients for each block
  3. Reshuffle the blocks into their new order (otherwise the 8x8 blocks would be rotated but still in the old place)
  4. Recompress it all with the lossless compression steps.
維他命╮ 2024-07-20 12:43:12

绝对 - 只需更改 EXIF 数据中的方向值即可。 绝大多数图像程序都会遵循此设置并显示“旋转”的图片。

如果某些条件成立,也可以“手动”(例如以编程方式)以无损方式旋转图像 - 旋转必须为 90/180 度,并且宽度/高度必须是块大小的倍数。 您也可以翻转/镜像它。 我不知道图像程序是否足够智能来特殊处理此操作。 我猜不会。

Absolutely - just change the orientation value in the EXIF data. The vast majority of image programs will respect this setting and show the picture "rotated".

It's also possibly to "manually" (e.g. programatically) rotate the image in a lossless fashion if certain criteria are true - rotation must be 90/180 degrees and the width/height must multiples of the block-size. You can also flip/mirror it. I don't know whether image programs are smart enough to special-case this operation though. I would guess not.

貪欢 2024-07-20 12:43:12

来自 JPEG 常见问题解答

“有一些专门的
可以对 JPEG 执行的操作
文件而不解压它,并且
因此不会招致
通常情况下的代际损失
从加载和重新保存中获取
常规图像编辑器中的图像。 在
特别是可以做
90 度旋转和翻转
无损,如果图像尺寸
是文件块的倍数
尺寸(通常为 16x16、16x8 或 8x8
彩色 JPEG 的像素)。
...

但是你确实需要特殊的软件; 在常规图像编辑器中旋转图像不会是无损的。”

From the JPEG FAQ:

"There are a few specialized
operations that can be done on a JPEG
file without decompressing it, and
thus without incurring the
generational loss that you'd normally
get from loading and re-saving the
image in a regular image editor. In
particular it is possible to do
90-degree rotations and flips
losslessly, if the image dimensions
are a multiple of the file's block
size (typically 16x16, 16x8, or 8x8
pixels for color JPEGs).
...

But you do need special software; rotating the image in a regular image editor won't be lossless."

江挽川 2024-07-20 12:43:12

不是 jpg 专家,但对于 90、180、270 度旋转,答案似乎是“是”。 (甚至可能适用于 360!:))

Not a jpg expert, but it seems that the answer would be Yes for 90, 180, 270 degree rotations. (maybe even for 360! :))

甜心 2024-07-20 12:43:12

是的,这是可能的。
谷歌快速搜索给出了执行此操作的程序列表

Yes, it is possible.
A quick google search gave this list of programs which do this

枕梦 2024-07-20 12:43:12

除非您旋转 90 度的倍数,否则您的图像将必须执行某种插值,这可能会降低图像质量。 使用良好的插值算法在这里会有所帮助。

至于打开和重新压缩,我不确定你实际上会得到更差的质量,但我不确定 JPEG 到底是如何工作的。

我建议你尝试压缩、操作和重新压缩,然后亲自看看结果是否足够好。 什么足够好取决于您的应用。

Unless you rotate by multiples of 90 degrees then your image will have to perform some kind of interpolation which might reduce the quality of your image. Using a good interpolation algorithm will help here.

As for opening and recompressing, I am not sure you would actually get worse quality, but then I am not sure exactly how JPEG works.

I suggest you try to compress, manipulate and recompress and see for yourself if the result is good enough. What is good enough is subject to your application.

柳若烟 2024-07-20 12:43:12

根据 Sean McHugh 撰写的关于了解数字图像插值的优秀文章:

每次旋转或扭曲图像时也会发生插值。 (...)
90° 旋转是无损的,因为无需重新定位像素
到两个像素之间的边界(因此被分割)。

并最终得出结论

尽可能避免旋转照片; 如果照片不平整
需要它,旋转不超过一次。

According to the excellent article on Understanding Digital Image Interpolation by Sean McHugh:

Interpolation also occurs each time you rotate or distort an image. (...)
The 90° rotation is lossless because no pixel ever has to be repositioned
onto the border between two pixels (and therefore divided).

and eventually concludes with

avoid rotating your photos when possible; if an unleveled photo
requires it, rotate no more than once.

左秋 2024-07-20 12:43:12

如果它可以帮助:

尝试比 Microsoft(Windows 7)本机图片查看器及其右键单击旋转选项做得更好,我尝试了以下链接的多个应用程序:http://jpegclub.org/losslessapps.html

例如,我尝试过 FastStone Image Viewer、XnView、Photosurfer、JPEG Lossless Rotator、ExifPro Image Viewer。

在简单的 90° 旋转后,它们中没有一个能比基本的 Windows 7 图片查看器产生更大的图片。
诚然,这么快下结论是有限的,但我目前还没有找到真正的无损旋转 .jpeg 应用程序,无论如何也不比内置的 Windows 应用程序更好。

If it can help :

Trying to do better than the Microsoft (Windows 7) native picture viewer and its right-click rotation options, I tried several apps of the following link : http://jpegclub.org/losslessapps.html

For instance, I tried FastStone Image Viewer, XnView, Photosurfer, JPEG Lossless Rotator, ExifPro Image Viewer.

NONE of them yields a bigger picture than the basic Windows 7 picture viewer after a simple 90° rotation.
It's admittedly limited to conclude so quickly, but I still don't have found a real lossless rotation .jpeg app for the moment, and in any case not better than the built-in Windows one.

我一直都在从未离去 2024-07-20 12:43:12

如果您谈论的是旋转 JPEG 图像,那么就没有进一步的压缩,对吗? 它与旋转像素位置有关。

使用任何程序进行旋转都可能会改变中间尺寸,因为它需要保留原始图像,这可能是一个需要考虑的问题。

If you are talking of rotating a JPEG image then there is no further compression right? It is about rotating pixel locations.

Doing rotation with any program will potentially change intermediate dimensions, as it needs to preserver original image, this may be an issue to consider.

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