硬汉嵌入式论坛

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

[LibJPEG] 【LibJPEG专题系列八】色彩量化

[复制链接]

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
发表于 2015-4-18 17:17:03 | 显示全部楼层 |阅读模式
                                       Section - [8] What is color quantization?

Many people don't have full-color (24 bit per pixel) display hardware.Inexpensive display hardware stores 8 bits per pixel, so it
can displayat most 256 distinct colors at a time.  To display a full-color image, thecomputer must choose an appropriate set of
representative colors and map the image into these colors.  This process is called "color quantization". (This is something of a
misnomer; "color selection" or "color reduction" would be a better term.  But we're stuck with the standard usage.)


Clearly, color quantization is a lossy process.  It turns out that for most images, the details of the color quantization algorithm
have *much* more impact on the final image quality than do any errors introduced by JPEG itself (except at the very lowest
JPEG quality settings).  Making a good color quantization method is a black art, and no single algorithm is best for all images.


Since JPEG is a full-color format, displaying a color JPEG image on 8-bit-or-less hardware requires color quantization.  The
speed and image quality of a JPEG viewer running on such hardware are largely determined by its quantization algorithm.  
Depending on whether a quick-and-dirty or good-but-slow method is used, you'll see great variation in image quality among
viewers on 8-bit displays, much more than occurs on 24-bit displays.


On the other hand, a GIF image has already been quantized to 256 or fewer colors.  (A GIF always has a specific number of
colors in its palette, and the format doesn't allow more than 256 palette entries.)  GIF has the advantage that the image maker
precomputes the color quantization, so viewers don't have to; this is one of the things that make GIF viewers faster than JPEG
viewers.  But this is also the *disadvantage* of GIF: you're stuck with the image maker's quantization.  If the maker quantized
to a different number of colors than what you can display, you'll either waste display capability or else have to requantize to
reduce the number of colors (which usually results in much poorer image quality than quantizing once from a full-color image).  
Furthermore, if the maker didn't use a high-quality color quantization algorithm, you're out of luck --- the image is ruined.


For this reason, JPEG promises significantly better image quality than GIF for all users whose machines don't match the image
maker's display hardware. JPEG's full color image can be quantized to precisely match the viewer's display hardware.  
Furthermore, you will be able to take advantage of future improvements in quantization algorithms, or purchase better display
hardware, to get a better view of JPEG images you already have.  With a GIF, you're stuck forevermore with what was sent.

A closely related problem is seen in many current World Wide Web browsers: when running on an 8-bit display, they force all
images into a pre-chosen palette.  (They do this to avoid having to worry about how to allocate the limited number of available
color slots among the various items on a Web page.)  A GIF version of a photo usually degrades very badly in this situation,
because it's effectively being forced through a second quantization step.  A JPEG photo won't look wonderful either, but it will
look less bad than the GIF equivalent because it's been quantized only once.


A growing number of people have better-than-8-bit display hardware already: 15- or 16-bit/pixel "high color" displays are
now quite common, and true 24-bit/pixel displays are no longer rare.  For these people, GIF is already obsolete, as it cannot
represent an image to the full capabilities of their display.  JPEG images can drive these displays much more effectively.


In short, JPEG is an all-around better choice than GIF for representing photographic images in a machine-independent fashion.


It's sometimes thought that a JPEG converted from a GIF shouldn't require color quantization.  That is false; even when you
feed a 256-or-less-color GIF into JPEG, what comes out of the decompressor is not 256 colors, but thousands of colors.  This
happens because JPEG's lossiness affects each pixel a little differently, so two pixels that started with identical colors will
usually come out with slightly different colors.  Considering the whole image, each original color gets "smeared" into a cluster
of nearby colors. Therefore quantization is always required to display a color JPEG on a colormapped display, regardless of
the image source.


The same effect makes it nearly meaningless to talk about the number of colors used by a JPEG image.  Even if you tried to
count the number of distinct pixel values, different JPEG decoders would give you different results because of roundoff
error differences.  I occasionally see posted images described as "256-color JPEG".  This tells me that the poster (a) hasn't
read this FAQ and (b) probably converted the JPEG from a GIF. JPEGs can be classified as color or gray-scale, but
number of colors just isn't a useful concept for JPEG, any more than it is for a real photograph.
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

740

主题

1326

回帖

3546

积分

管理员

春暖花开

Rank: 9Rank: 9Rank: 9

积分
3546
QQ
 楼主| 发表于 2015-4-18 17:20:50 | 显示全部楼层
                                                     Section 8—色彩量化?

    许多人没有全彩的(每像素24)显示硬件。廉价的显示硬件存储每像素8位的信息,所以它只能同时显示最多256
不同的颜色。为了显示一个全彩的图像,计算机必须选择一个合适的代表性颜色组,并且将图像映射到这些颜色上。这个
过程就叫做“色彩量化”。(这有点用词不当;“色彩选择”或“色彩还原”会是一个更好的词语。但是我们不得不接受
标准用法。)


    很明显,色彩量化是一个有损的过程。事实上,对于大多数的图像,色彩量化的算法细节对最终的图像质量,比起
JPEG本身引入的缺陷(非常低的JPEG质量设置除外)有更大更大的影响。制定一个好的色彩量化的方法是一种艺术,而
且对于所有的图像来说,没有任何一个单一的算法是最好的。


    因为JPEG是一种全彩格式,在8位或更少的硬件上显示彩色JPEG图像就需要色彩量化。JPEG查看器在这样的硬件上
运行所需的速度以及图像质量在很大程度上取决于它的量化算法。具体取决于是使用快并糟糕或是慢却良好的的方法,在
8位显示器上你会看到图像质量之间非常大的改变,比起24位显示器上的变化更明显。


     另一方面,GIF图像已经被量化到256种或更少的颜色。(GIF总是在它的调色板中有一个特定的颜色数字,而且这种格
式不允许超过256种调色板项目。)GIF具有图像制造者预计色彩量化的优势,所以图像查看器则不必有;这一点就使得
GIF查看器比JPEG查看器更快。但是,这对于GIF来说也是一把“双刃剑”:你不得不接受图像制造者的量化。如果制造
者量化到一个与你可以显示的不同数量的颜色,你要么浪费显示能力,否则你必须重新量化来减少色彩的数量(而相对于
只量化一次的全彩图像来说,这通常导致差得多的图像质量)。进一步而言,如果制造者没有使用一个高质量的色彩量化
算法,那你就不走运了——图像早就被毁了。


    由于这个原因,JPEG向所有用户(其计算机不能匹配图像制造者的显示硬件要求)承诺比GIF显著更好的图像质量。
JPEG的全彩图像可以被量化到精确匹配图像查看器的显示硬件。此外,你可以利用未来量化算法改进的优势,或者购买
更好的显示硬件,来得到一个更好的JPEG图像的显示效果。使用GIF,你就不得不永远接受已经被发送好的数据。

    在许多万维网浏览器中出现的一个密切相关的问题:当计算机在一个8位显示器上运行时,它们迫使所有图像使用一个
预先选择的调色板。(此举是为了避免担心在网页的不同项目中,怎样分配有限数量的可用色彩插槽。)一张相片的GIF
版本在这种情况下通常退化的很严重,是因为它被强制有效的进行了二次量化。JPEG版本的照片看起来也不是很完美,但
看起来不会比GIF更糟糕,因为它只量化了一次。


    越来越多的人们已经有了比8位显示器更好的硬件:每像素1516位高彩显示是相当常见,而且真正每像素24位显示也
不再罕见。对于这些人们,GIF已经过时了,因为它不能代表一个图像所能显示的全部功能。JPEG图像可以更有效的驱动
这些显示器。


    总而言之,用一种与机器无关的方式,在代表摄影图像方面,JPEG是一种比GIF全面的更好的选择。   


    有时认为转化于GIFJPEG不应该需要色彩量化。那是错误的;即使当你向JPEG提供256或更少色彩时,解压器的色
彩却不是256种,而是上千种。因为JPEG的有损压缩会不同的影响每个像素,所以具有相同颜色的两种颜色将通常会变成
稍微不一样的颜色。考虑到整个图像,每一个原来的颜色会被“涂抹”到附近的颜色群。因此,忽略图像来源,量化总是
需要在一个彩色映射的显示器上显示彩色JPEG


    同样的效果使得谈论JPEG图像使用的色彩数量变得毫无意义。即使你试图计算不同像素值的数量,由于舍入误差的差
异,不同的JPEG解码器会给出不同的结果。偶尔会看到被称为“256JPEG”的海报图像。这告诉我们,该海报a.还没有
读过本章FAQb.有可能是从GIF转化的来的JPEG图像。JPEG图像可以分类为彩色或灰度图像,但是色彩的数量对于JPEG
来说并不是一个有用的概念,这一点和真实照片的情况不一样。
努力打造安富莱高质量微信公众号:点击扫描图片关注
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-11 23:57 , Processed in 0.223467 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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