能否在不损失质量的情况下旋转 JPEG 压缩图像?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
有一个名为 jpegtran 的程序
要无损旋转图像,您可以执行以下操作:
这里是提供基于 JPEG 无损旋转功能的应用程序列表关于 IJG 代码
There is a program named jpegtran
To rotate the image losslessly, you can do the following:
And Here is a list of applications which provide the JPEG lossless rotation feature based on the IJG code
是的,在某些情况下是可能的:图像进行 90 度旋转和翻转。 JPEG 算法的核心(有损部分)涉及将图像分解为 8x8 像素块,执行 对块进行离散余弦变换,然后量化结果。 除此之外还有一些颜色空间转换和块的无损压缩。
旋转或翻转 8x8 块将给出具有相同基本系数的 DCT,但可能会转置和/或根据变换进行一些符号更改。 因此,无损旋转或翻转图像的基本步骤包括:
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:
绝对 - 只需更改 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.
来自 JPEG 常见问题解答:
From the JPEG FAQ:
不是 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! :))
是的,这是可能的。
谷歌快速搜索给出了执行此操作的程序列表
Yes, it is possible.
A quick google search gave this list of programs which do this
除非您旋转 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.
根据 Sean McHugh 撰写的关于了解数字图像插值的优秀文章:
并最终得出结论
According to the excellent article on Understanding Digital Image Interpolation by Sean McHugh:
and eventually concludes with
如果它可以帮助:
尝试比 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.
如果您谈论的是旋转 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.