硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4869|回复: 1
收起左侧

[LibJPEG] 【LibJPEG专题系列十】反复压缩/解压缩的损失

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-4-25 15:26:39 | 显示全部楼层 |阅读模式
                                 Section - [10] Does loss accumulate
                        with repeated compression/decompression?

It would be nice if, having compressed an image with JPEG, you could decompress it, manipulate it (crop off a border,
say), and recompress it without any further image degradation beyond what you lost initially. Unfortunately THIS IS
NOT THE CASE.  In general, recompressing an altered image loses more information.  Hence it's important to minimize
the number of generations of JPEG compression between initial and final versions of an image.


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).  This fact used to be just an academic curiosity,
but it has assumed practical importance recently because many users of digital cameras would like to be able to rotate
their images from landscape to portrait format without incurring loss --- and practically all digicams that produce JPEG
files produce images of the right dimensions for these operations to work.  So software that can do lossless JPEG
transforms has started to pop up.  But you do need special software; rotating the image in a regular image editor won't
be lossless.


It turns out that if you decompress and recompress an image at the same quality setting first used, relatively little
further degradation occurs. This means that you can make local modifications to a JPEG image without material
degradation of other areas of the image.  (The areas you change will still degrade, however.)  Counterintuitively, this
works better the lower the quality setting.  But you must use *exactly* the same setting, or all bets are off.  Also, the
decompressed image must be saved in a full-color format; if you do something like JPEG=>GIF=>JPEG, the color
quantization step loses lots of information.


Unfortunately, cropping doesn't count as a local change!  JPEG processes the image in small blocks, and cropping
usually moves the block boundaries, so that the image looks completely different to JPEG.  You can take advantage
of the low-degradation behavior if you are careful to crop the top and left margins only by a multiple of the block
size (typically 16 pixels), so that the remaining blocks start in the same places.  (True lossless cropping is possible
under the same restrictions about where to crop, but again this requires specialized software.)


The bottom line is that JPEG is a useful format for compact storage and transmission of images, but you don't want
to use it as an intermediate format for sequences of image manipulation steps.  Use a lossless 24-bit format (PNG,
TIFF, PPM, etc) while working on the image, then JPEG it when you are ready to file it away or send it out on the
net.  If you expect to edit your image again in the future, keep a lossless master copy to work from.  The JPEG you
put up on your Web site should be a derived copy, not your editing master.
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-4-27 17:42:01 | 显示全部楼层
                                         Section 10—反复压缩/解压缩的损失

    已经被JPEG压缩的图像,如果在最初的损失之外没有更多图像退化的情况下,你可以对其进行解压缩、操作(比如,减掉
一条边界)以及再压缩——这将是极好的。不幸的是,根本就不是这么回事!一般情况下,对已被处理过的图像进行再压缩将
会损失更多的图像信息。因此,在最初的和最终的图像之间,最大限度地减少JPEG压缩的次数是很重要的。


    这里有一些专门的操作可以使用在JPEG文件上,而无需对其进行再压缩,从而不会在常规图像编辑器中正常加载以及重新
保存该图像时产生多余的损失(generational loss)。特别是,当图像的尺寸是文件块大小(对于彩色JPEG文件来说,通常是
6x16 16x88x8像素的)的整数倍时,有可能实现90度的无损旋转和翻转。这一事实过去只是一个理论上的猜测,但是最
近它已表现出了重要的现实意义,因为很多的数码相机用户希望在没有损失产生的情况下能够实现图像从横向到纵向格式的旋
转——几乎所有生成JPEG文件的数码相机都可以通过这些操作生成尺寸合适的图像。因此,可以实现无损JPEG转换的软件流
行开来。但是,在常规图像编辑器中转换图像将不会是无损的;因此需要特殊的软件。


    事实证明,如果是在首次使用相同的质量设置参数下解压缩以及再压缩图像,那么相对来说,将会产生较少的进一步图像
退化。这就意味着,在其他区域的元素没有退化的情况下,可以对JPEG图像进行局部修改。(然而,你修改的区域仍会退化。
与直觉相反,质量设置参数越低,效果则越好。但是,你必须使用完全相同的设置,否则全盘皆输。同时,解压缩后的图像必
须保存为全彩的格式;如果你像JPEG=>GIF=>JPEG这样做,色彩量化的步骤将会损失大量的信息。


    不走运的是,剪裁却不算是局部变化!JPEG将图像处理成小块,裁剪通常移动块的边界,以使得图像看起来完全不同于
JPEG。如果你仔细剪裁图像顶部,并且只留下块大小倍数(通常是16像素)的边缘,这样,使剩余的块还留在原来的位置。
(真正的无损剪裁受限于剪裁的位置,同样的,这需要专门的软件。)


    JPEG作为一种用于小容量存储以及图像传输的有用的格式是底线,但不希望将它作为图像处理步骤序列的中间格式。处理
图像时使用无损的24位格式(PNG, TIFF, PPM),那么,当你准备将它归档或是发送出去时,通过JPEG对其处理。如果你
希望以后再次编辑图像,则继续使用无损的主文件。放到网站上的JPEG应该是编辑后的副本,而不是主副本。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-11 22:56 , Processed in 0.151789 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表