jpg 文件格式详解
jpg格式名词解释

jpg格式名词解释
JPG格式是一种最常用的图像文件格式,全称是JPEG(Joint Photographic Experts Group),文件后缀名为“.jpg”或“.jpeg”。
它是一种有损压缩格式,由一个软件开发联合会组织制定。
JPG格式能够将图像压缩在很小的储存空间,图像中重复或不重要的资料会被丢失,因此容易造成图像数据的损伤。
尤其是使用过高的压缩比例,将使最终解压缩后恢复的图像质量明显降低,如果追求高品质图像,不宜采用过高压缩比例。
但是,JPG压缩技术十分先进,它用有损压缩方式去除冗余的图像数据,在获得极高的压缩率的同时能展现十分丰富生动的图像,换句话说,就是可以用最少的磁盘空间得到较好的图像品质。
以上内容仅供参考,如需更多信息,建议查阅相关文献或咨询专业人士。
jpg是什么意思

jpg是什么意思
jpg即图像静态压缩模式,是面向连续色调静止图像的一种压缩标准,也是最常用的图像文件格式,还可以写作jpeg。
Jpg 格式的压缩率极高,并且尺寸较小,传输速度快。
网络上,在一句话后面加上jpg,表示假象的表情包和图像,给人一种画面感。
jpg即图像静态压缩模式,是面向连续色调静止图像的一种压缩标准,也是最常用的图像文件格式,还可以写作jpeg。
在网页中使用的图像,多为jpeg格式。
Jpg格式的压缩率极高,并且能很好的再现全彩色的图像,同时文件尺寸较小,使传输和下载速度大大加快,但是,并非所有网页都支持jpg格式,并且在压缩时,可能会使图像的质量受到损失。
网络上,在一句话后面加上jpg,可以表示假象的表情包和图像,给人一种画面感,比如“微笑,jpg”“拍了拍你的头,jpg”,是年轻人常用的一种聊天方式,增加了交流的丰富性和趣味性。
JPEG图像格式详解

JPEG图像格式详解JPEG压缩简介-------------1.色彩模型JPEG的图片使用的是YCrCb颜色模型,而不是计算机上最常用的RGB.关于色彩模型,这里不多阐述.只是说明,YCrCb模型更适合图形压缩.因为人眼对图片上的亮度Y的变化远比色度C的变化敏感.我们完全可以每个点保存一个8bit的亮度值,每2x2个点保存一个Cr Cb值,而图象在肉眼中的感觉不会起太大的变化.所以,原来用RGB模型,4个点需要4x3=12字节.而现在仅需要4+2=6字节;平均每个点占12bit.当然JPEG格式里允许每个点的C值都记录下来;不过MPEG里都是按12bit一个点来存放的,我们简写为YUV12.[R G B]->[Y Cb Cr]转换-------------------------(R,G,B都是8bit unsigned)|Y||0.2990.5870.114||R||0||Cb|=|-0.1687-0.33130.5|*|G|+|128||Cr||0.5-0.4187-0.0813||B||128|Y=0.299*R+0.587*G+0.114*B(亮度)Cb=-0.1687*R-0.3313*G+0.5*B+128Cr=0.5*R-0.4187*G-0.0813*B+128[Y,Cb,Cr]->[R,G,B]转换-------------------------R=Y+ 1.402*(Cr-128)G=Y-0.34414*(Cb-128)-0.71414*(Cr-128)B=Y+ 1.772*(Cb-128)一般,C值(包括Cb Cr)应该是一个有符号的数字,但这里被处理过了,方法是加上了128.JPEG里的数据都是无符号8bit的.2.DCT(离散余弦变换)JPEG里,要对数据压缩,先要做一次DCT变换.DCT变换的原理,涉及到数学知识,这里我们不必深究.反正和傅立叶变换(学过高数的都知道)是差不多了.经过个点为一个单位处理的.所以如果原始图片的长宽不是8的倍数,都需要先补成8的倍数,好一块块的处理.另外,记得刚才我说的Cr Cb都是2x2记录一次吗?所以大多数情况,是要补成16x16的整数块.按从左到右,从上到下的次序排列(和我们写字的次序一样).JPEG里是对Y Cr Cb分别做DCT变换的.这里进行DCT变换的Y,Cr,Cb值的范围都是-128~127.(Y被减去128)JPEG编码时使用的是Forward DCT(FDCT)解码时使用的Inverse DCT(IDCT)下面给出公式:FDCT:772*x+12*y+1F(u,v)=alpha(u)*alpha(v)*sum sum f(x,y)*cos(-------*u*PI)*cos(------*v*PI)x=0y=01616u,v=0,1,...,7{1/sqrt(8)(u==0)alpha(u)={{1/2(u!=0)IDCT:772*x+12*y+1f(x,y)=sum sum alpha(u)*alpha(v)*F(u,v)*cos(-------*u*PI)*cos(------*v*PI) u=0v=01616x,y=0,1 (7)这个步骤很花时间,另外有种AA&N优化算法,大家可以去inet自己找一下.在Intel主页上可以找到AA&N IDCT的MMX优化代码.(Intel主页上的代码,输入数据为12.4的定点数,输入矩阵需要转置90度)3.重排列DCT结果DCT将一个8x8的数组变换成另一个8x8的数组.但是内存里所有数据都是线形存放的,如果我们一行行的存放这64个数字,每行的结尾的点和下行开始的点就没有什么关系,所以JPEG规定按如下次序整理64个数字.0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,35,36,48,49,57,58,62,63这样数列里的相邻点在图片上也是相邻的了.4.量化对于前面得到的64个空间频率振幅值,我们将对它们作幅度分层量化操作.方法就是分别除以量化表里对应值并四舍五入.for(i=0;i<=63;i++)vector[i]=(int)(vector[i]/quantization_table[i]+0.5)下面有张JPEG标准量化表.(按上面同样的弯曲次序排列)1611101624405161121214192658605514131624405769561417222951878062182237566810910377243555648110411392496478871031211201017292959811210010399这张表依据心理视觉阀制作,对8bit的亮度和色度的图象的处理效果不错.当然我们可以使用任意的量化表.量化表是定义在jpeg的DQT标记后.一般为Y值定义一个,为C值定义一个.量化表是控制JPEG压缩比的关键.这个步骤除掉了一些高频量,损失了很高细节.但事实上人眼对高空间频率远没有低频敏感.所以处理后的视觉损失很小.另一个重要原因是所有的图片的点与点之间会有一个色彩过渡的过程.大量的图象信息被包含在低空间频率中.经过量化处理后,在高空间频率段,将出现大量连续的零.注意,量化后的数据有可能超过2byte有符号整数的处理范围.5.0RLE编码现在我们矢量中有许多连续的0.我们可以使用RLE来压缩掉这些0.这里我们将跳过第一个矢量(后面将解释为什么)因为它的编码比较特别.假设有一组矢量(64个的后63个)是57,45,0,0,0,0,23,0,-30,-16,0,0,1,0,0,0,0,0,0,0,..,0经过RLE压缩后就是(0,57);(0,45);(4,23);(1,-30);(0,-16);(2,1);EOBEOB是一个结束标记,表示后面都是0了.实际上,我们用(0,0)表示EOB但是,如果这组数字不以0结束,那么就不需要EOB.另外需要注意的是,由于后面huffman编码的要求,每组数字前一个表示0的数量的必须是4bit,就是说,只能是0~15,所以,如果有这么一组数字:我们实际这样编码:(0,57);(15,0)(2,3);(4,2);(15,0)(15,0)(1,895),(0,0)注意(15,0)表示了16个连续的0.6.huffman编码为了提高储存效率,JPEG里并不直接保存数值,而是将数值按位数分成16组:数值组实际保存值00--1,110,1-3,-2,2,3200,01,10,11-7,-6,-5,-4,4,5,6,73000,001,010,011,100,101,110,111 -15,..,-8,8,..,1540000,..,0111,1000,..,1111-31,..,-16,16,..,31500000,..,01111,10000,..,11111-63,..,-32,32,..,636.-127,..,-64,64,..,1277.-255,..,-128,128,..,2558.-511,..,-256,256,..,5119.-1023,..,-512,512,..,102310.-2047,..,-1024,1024,..,204711.-4095,..,-2048,2048,..,409512.-8191,..,-4096,4096,..,819113.-16383,..,-8192,8192,..,1638314.-32767,..,-16384,16384,..,3276715.还是来看前面的例子:(0,57);(0,45);(4,23);(1,-30);(0,-8);(2,1);(0,0)只处理每对数右边的那个:57是第6组的,实际保存值为111001,所以被编码为(6,111001)45,同样的操作,编码为(6,101101)23->(5,10111)-30->(5,00001)-8->(4,0111)1->(1,1)前面的那串数字就变成了:(0,6),111001;(0,6),101101;(4,5),10111;(1,5),00001;(0,4),0111;(2,1),1;(0,0)括号里的数值正好合成一个字节.后面被编码的数字表示范围是-32767..32767.合成的字节里,高4位是前续0的个数,低4位描述了后面数字的位数.继续刚才的例子,如果06的huffman编码为111000(06对应111000为查表所得.对应成1~16bits的不定长数值.出现频率高的数字小于8bits,频率低的大于8bits,从而使整个的数据长度降低,关于huffman压缩算法,请查阅相关资料)69=(4,5)---1111111110011001(注:69=4*16+5=0x45)21=(1,5)---111111101104=(0,4)---101133=(2,1)---110110=EOB=(0,0)---1010那么最后对于前面的例子表示的63个系数(记得我们将第一个跳过了吗?)按位流写入JPG文件中就是这样的: 1110001110011110001011011111111110011001101111111111011000001 1011011111011110107.DC的编码-----------记得刚才我们跳过了每组64个数据的第一个吧,DC就是指的这个数字(后面63个简称AC)代入前面的FDCT公式可以得到c(0,0)77DC=F(0,0)=---------*sum sum f(x,y)*cos0*cos0其中c(0,0)=1/24x=0y=0177=---*sum sum f(x,y)8x=0y=0即一块图象样本的平均值.就是说,它包含了原始8x8图象块里的很多能量.(通常会得到一个很大的数值)JPEG的作者指出连续块的DC率之间有很紧密的联系,因此他们决定对8x8块的DC值的差别进行编码.(Y,Cb,Cr分别有自己的DC)Diff=DC(i)-DC(i-1)所以这一块的DC(i)就是:DC(i)=DC(i-1)+DiffJPG从0开始对DC编码,所以DC(0)=0.然后再将当前Diff值加在上一个值上得到当前值.下面再来看看上面那个例子:(记住我们保存的DC是和上一块DC的差值Diff)例如上面例子中,Diff是-511,就编码成如果9的Huffman编码是1111110(在JPG文件中,一般有两个Huffman表,一个是DC用,一个是AC用)那么在JPG文件中,DC的2进制表示为1111110000000000它将放在63个AC的前面,上面上个例子的最终BIT流如下:1111110000000000111000111001111000101101111111111001100110111 1111111011000001101101111101111010解码过程简述-------------8.一个数据单元Y的解码(其余类同)--------------------------------在整个图片解码的开始,你需要先初始化DC值为0.1)先解码DC:a)取得一个Huffman码(使用Huffman DC表)b)Huffman解码,看看后面的数据位数Nc)取得N位,计算Diff值d)DC+=Diffe)写入DC值:"vector[0]=DC"2)解码63个AC:-------循环处理每个AC直到EOB或者处理到64个ACa)取得一个Huffman码(使用Huffman AC表)b)Huffman解码,得到(前面0数量,组号)[记住:如果是(0,0)就是EOB了]c)取得N位(组号)计算ACd)写入相应数量的0e)接下来写入AC-----------------下一步的解码------------上一步我们得到了64个矢量.下面我们还需要做一些解码工作:2)重排列64个矢量到8x8的块中3)对8x8的块作IDCT对8x8块的(Y,Cb,Cr)重复上面的操作[Huffman解码,步骤1),2),3)]4)将所有的8bit数加上1285)转换YCbCr到RGB9.JPG文件(Byte级)里怎样组织图片信息-----------------------------------注意JPEG/JFIF文件格式使用Motorola格式,而不是Intel格式,就是说,如果是一个字的话,高字节在前,低字节在后.JPG文件是由一个个段(segments)构成的.每个段长度<=65535.每个段从一个标记字开始.标记字都是0xff打头的,以非0字节和0xFF结束.例如'FFDA','FFC4','FFC0'.每个标记有它特定意义,这是由第2字节指明的.例如,SOS(Start Of Scan='FFDA')指明了你应该开始解码.另一个标记DQT(Define Quantization Table=0xFFDB)就是说它后面有64字节的quantization表在处理JPG文件时,如果你碰到一个0xFF,而它后面的字节不是0,并且这个字节没有意义.那么你遇到的0xFF字节必须被忽略.(一些JPG里,常用用0xFF做某些填充用途)如果你在做huffman编码时碰巧产生了一个0xFF,那么就用0xFF0x00代替.就是说在jpeg图形解码时碰到FF00就把它当作FF处理.另外在huffman编码区域结束时,碰到几个bit没有用的时候,应该用1去填充.然后后面跟FF.下面是几个重要的标记--------------------SOI=Start Of Image='FFD8'这个标记只在文件开始出现一次EOI=End Of Image='FFD9'JPG文件都以FFD9结束RSTi=FFDi(i=0..7)[RST0=FFD0,RST7=FFD7]=复位标记通常穿插在数据流里,我想是担心JPG解码出问题吧(应该配合DRI使用).RST将Huffman的解码数据流复位.DC也重新从0开始计(SOS---RST0---RST1--RST2--......--RST6---RST7--RST0--...)10.标记-------下面是必须处理的标记SOF0=Start Of Frame0=FFC0SOS=Start Of Scan=FFDAAPP0=it's the marker used to identify a JPG file which uses the JFIF specification=FFE0COM=Comment=FFFEDNL=Define Number of Lines=FFDCDRI=Define Restart Interval=FFDDDQT=Define Quantization Table=FFDBDHT=Define Huffman Table=FFC411.JPG文件中Haffman表的储存-----------------------------JPEG里定义了一张表来描述Haffman树.定义在DHT标记后面.注意:Haffman代码的长度限制在16bit内.一般一个JPG文件里会有2类Haffman表:一个用于DC一个用于AC(实际有4个表,亮度的DC,AC两个,色度的DC,AC两个)这张表是这样保存的:1)16字节:第i字节表示了i位长的Huffman代码的个数(i=1到16)2)这表的长度(字节数)=这16个数字之和现在你可以想象这张表怎么存放的吧?对应字节就是对应Haffman代码等价数字.我不多解释,这需要你先了解Haffman算法.这里只举一个例子:Haffman表的表头是0,2,3,1,1,1,0,1,0,0,0,0,0,0,0,0就是说长度为1的代码没有长度为2的代码为0001长度为3的代码是100101110长度为4的代码是1110长度为5的代码是11110长度为6的代码是111110长度为7的代码没有(如果有一个的话应该是1111110)长度为8的代码是11111100.....如果表下面的数据是4557291723253428就是说45=0057=0129=10017=10123=110等等...如果你懂Haffman编码,这些不难理解12.采样系数-----------下面讲解的都是真彩JPG的解码,灰度JPG的解码很简单,因为图形中只有亮度信息.而彩色图形由(Y,Cr,Cb)构成,前面提到过,Y通常是每点采样一次,而Cr, Cb一般是2x2点采样一次,当然也有的JPG是逐点采样,或者每两点采样(横向两点,纵向一点)采样系数均被定义成对比最高采样系数的相对值.一般情况(即:Y逐点采样,Cr Cb每2x2点一次)下:Y有最高的采样率,横向采样系数HY=2纵向采样系数VY=2;Cb的横向采样系数HCb=1,纵向采样系数VCb=1;同样HCr=1,VCr=1在Jpeg里,8x8个原始数据,经过RLE,Huffman编码后的一串数据流称为一个Data Unit(DU)JPG里按DU为单位的编码次序如下:1)for(counter_y=1;counter_y<=VY;counter_y++)for(counter_x=1;counter_x<=HY;counter_x++){对Y的Data Unit编码}2)for(counter_y=1;counter_y<=VCb;counter_y++)for(counter_x=1;counter_x<=HCb;counter_x++){对Cb的Data Unit编码}3)for(counter_y=1;counter_y<=VCr;counter_y++)for(counter_x=1;counter_x<=HCr;counter_x++){对Cr的Data Unit编码}按我上面的例子:(HY=2,VY=2;HCb=VCb=1,HCr,VCr=1)就是这样一个次序YDU,YDU,YDU,YDU,CbDU,CrDU这些就描述了一块16x16的图形.16x16=(Hmax*8x Vmax*8)这里Hmax=HY=2一个(Hmax*8,Vmax*8)的块被称作MCU(Minimun Coded Unix)前面例子中一个MCU=YDU,YDU,YDU,YDU,CbDU,CrDU如果HY=1,VY=1HCb=1,VCb=1HCr=1,VCr=1这样(Hmax=1,Vmax=1),MCU只有8x8大,MCU=YDU,CbDU,CrDU对于灰度JPG,MCU只有一个DU(MCU=YDU)JPG文件里,图象的每个组成部分的采样系数定义在SOF0(FFC0)标记后13.简单说一下JPG文件的解码-------------------------解码程序先从JPG文件中读出采样系数,这样就知道了MCU的大小,算出整个图象有几个MCU.解码程序再循环逐个对MCU解码,一直到检查到EOI标记.对于每个MCU,按正规的次序解出每个DU,然后组合,转换成(R,G,B)就OK了附:JPEG文件格式~~~~~~~~~~~~~~~~-文件头(2bytes):$ff,$d8(SOI)(JPEG文件标识)-任意数量的段,见后面-文件结束(2bytes):$ff,$d9(EOI)段的格式:~~~~~~~~~-header(4bytes):$ff段标识n段的类型(1byte)sh,sl该段长度,包括这两个字节,但是不包括前面的$ff和n.注意:长度不是intel次序,而是Motorola的,高字节在前,低字节在后!-该段的内容,最多65533字节注意:-有一些无参数的段(下面那些前面注明星号的)这些段没有长度描述(而且没有内容),只有$ff和类型字节.-段之间无论有多少$ff都是合法的,必须被忽略掉.段的类型:*TEM=$01可以忽略掉SOF0=$c0帧开始(baseline JPEG),细节附后SOF1=$c1ditoSOF2=$c2通常不支持SOF3=$c3通常不支持SOF5=$c5通常不支持SOF6=$c6通常不支持SOF7=$c7通常不支持SOF9=$c9arithmetic编码(Huffman的一种扩展算法),通常不支持SOF10=$ca通常不支持SOF11=$cb通常不支持SOF13=$cd通常不支持SOF14=$ce通常不支持SOF14=$ce通常不支持SOF15=$cf通常不支持DHT=$c4定义Huffman Table,细节附后JPG=$c8未定义/保留(引起解码错误)DAC=$cc定义Arithmetic Table,通常不支持*RST0=$d0RSTn用于resync,通常被忽略*RST1=$d1*RST2=$d2*RST3=$d3*RST4=$d4*RST5=$d5*RST6=$d6*RST7=$d7SOI=$d8图片开始EOI=$d9图片结束SOS=$da扫描行开始,细节附后DQT=$db定义Quantization Table,细节附后DNL=$dc通常不支持,忽略DRI=$dd定义重新开始间隔,细节附后DHP=$de忽略(跳过)EXP=$df忽略(跳过)APP0=$e0JFIF APP0segment marker(细节略)APP15=$ef忽略JPG0=$f0忽略(跳过)JPG13=$fd忽略(跳过)COM=$fe注释,细节附后其它的段类型都保留必须跳过SOF0:Start Of Frame0:~~~~~~~~~~~~~~~~~~~~~~~-$ff,$c0(SOF0)-长度(高字节,低字节),8+components*3-数据精度(1byte)每个样本位数,通常是8(大多数软件不支持12和16) -图片高度(高字节,低字节),如果不支持DNL就必须>0-图片宽度(高字节,低字节),如果不支持DNL就必须>0-components数量(1byte),灰度图是1,YCbCr/YIQ彩色图是3,CMYK彩色图是4-每个component:3bytes-component id(1=Y,2=Cb,3=Cr,4=I,5=Q)-采样系数(bit0-3vert.,4-7hor.)-quantization table号DRI:Define Restart Interval:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-$ff,$dd(DRI)-长度(高字节,低字节),必须是4-MCU块的单元中的重新开始间隔(高字节,低字节),意思是说,每n个MCU块就有一个RSTn标记.第一个标记是RST0,然后是RST1等,RST7后再从RST0重复DQT:Define Quantization Table:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-$ff,$db(DQT)-长度(高字节,低字节)-QT信息(1byte):bit0..3:QT号(0..3,否则错误)bit 4..7:QT精度,0=8bit,否则16bit-n字节的QT,n=64*(精度+1)备注:-一个单独的DQT段可以包含多个QT,每个都有自己的信息字节-当精度=1(16bit),每个字都是高位在前低位在后DAC:Define Arithmetic Table:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~法律原因,现在的软件不支持arithmetic编码.不能生产使用arithmetic编码的JPEG文件DHT:Define Huffman Table:~~~~~~~~~~~~~~~~~~~~~~~~~~-$ff,$c4(DHT)-长度(高字节,低字节)-HT信息(1byte):bit0..3:HT号(0..3,否则错误)bit4:HT类型,0=DC table,1=AC tablebit 5..7:必须是0-16bytes:长度是 1..16代码的符号数.这16个数的和应该<=256 -n bytes:一个包含了按递增次序代码长度排列的符号表(n=代码总数)备注:-一个单独的DHT段可以包含多个HT,每个都有自己的信息字节COM:注释:~~~~~~~~~~-$ff,$fe(COM)-注释长度(高字节,低字节)=L+2-注释为长度为L的字符流SOS:Start Of Scan:~~~~~~~~~~~~~~~~~~~-$ff,$da(SOS)-长度(高字节,低字节),必须是6+2*(扫描行内组件的数量)-扫描行内组件的数量(1byte),必须>=1,<=4(否则是错的)通常是3 -每个组件:2bytes-component id(1=Y,2=Cb,3=Cr,4=I,5=Q),见SOF0-使用的Huffman表:-bit0..3:AC table(0..3)-bit 4..7:DC table(0..3)-忽略3bytes(???)备注:-图片数据(一个个扫描行)紧接着SOS段.。
jpeg文件格式标准

jpeg文件格式标准摘要:本文介绍了JPEG文件格式标准的基本知识,包括其历史背景、文件结构、压缩算法以及应用领域。
通过深入理解JPEG文件格式标准,读者可以更好地掌握该标准的使用和应用。
1. 简介JPEG,全称为Joint Photographic Experts Group,是一种常用的图像压缩格式。
该格式广泛应用于数字摄影、图像处理、图像存储等领域。
通过对图像进行有损压缩,JPEG可以在保持图片质量的同时减小文件大小,提高传输和存储的效率。
2. 历史背景JPEG文件格式标准最早于1992年发布。
它是由以同名组织命名的Joint Photographic Experts Group制定的。
该标准的制定旨在寻找一种通用的图像压缩方法,以适应当时数字图像处理领域的发展需求。
3. 文件结构JPEG文件由多个部分组成,其中最重要的是图像数据和文件头。
3.1 文件头JPEG文件头以SOI(Start of Image)标记开始,用于标识该文件是一个JPEG图像。
紧接着是APP(Application Segment)标记,用于存储一些可选信息,如图像的创建软件、版本等。
3.2 图像数据JPEG文件中的图像数据以帧(Frame)的形式存在。
一个JPEG文件可以包含多个帧,每个帧可以包含多个扫描(Scan)。
每个扫描由若干个组成,每个组包含了一组相邻的像素。
4. 压缩算法JPEG文件格式通过压缩算法实现对图像的有损压缩。
JPEG压缩算法主要包含两个过程:离散余弦变换(DCT)和量化。
4.1 离散余弦变换(DCT)DCT是一种常用的信号处理技术,用于将时域信号变换为频域信号。
在JPEG压缩中,DCT被用于将原始图像信号转换为一组频谱系数。
4.2 量化量化是JPEG压缩中的另一个重要步骤,它将DCT变换后的频谱系数进行量化处理。
通过设定不同的量化表,可以实现不同程度的压缩效果。
5. 应用领域JPEG文件格式在众多领域都有广泛应用,特别是数字摄影、图像处理和图像存储等方面。
JPG文件结构分析

JPG文件结构分析JPG(Joint Photographic Experts Group)是一种常见的图像文件格式,以其高压缩比和图像质量而闻名。
在本文中,将对JPG文件的结构进行分析。
1.文件头:JPG文件头部包含固定的标识符,用于识别文件类型。
通常,JPG文件的文件头为16个字节,其中包括"FFD8"的起始标志。
2.数据段:JPG文件的数据段是由多个标记组成的。
每个标记都由两个字节的起始标志"FF"和一个标记标识符组成。
标记标识符指示了将要跟随的数据类型或操作。
数据段中常见的标记包括APP0、DQT、SOF0、DHT、SOS等。
其中,APP0标记包含一些额外的信息,如JFIF(JPEG文件交换格式)版本号和文件创作的设备。
DQT(量化表定义)标记包含了量化表,这些表用于调整图像的颜色分辨率。
SOF0(帧头)标记包含了图像的宽度、高度以及色彩模式等信息。
DHT(霍夫曼表定义)标记包含了JPEG压缩算法所使用的霍夫曼编码表。
SOS(扫描开始)标记表示图像的实际数据开始。
3.图像数据:JPG文件的图像数据是压缩后的二进制流。
图像数据通常由几个扫描组成,每个扫描都由一个起始标记和相应的数据组成。
扫描包含的数据进行了特殊的编码处理,以实现高压缩比。
压缩算法主要包括离散余弦变换和霍夫曼编码。
在离散余弦变换中,图像被划分成8x8的块,每个块进行离散余弦变换,然后进行量化。
量化后的数据通过霍夫曼编码进行压缩。
4.文件尾:JPG文件尾部由一个16位的结束标记"FFD9"组成,用于表示图像数据的结束。
在JPG文件结构中,数据段是最重要的部分。
它包含了图像的所有信息,包括压缩参数、颜色信息和压缩后的图像数据。
图像数据经过JPEG压缩算法,可以有效地减小文件大小,并保持较高的图像质量。
总结起来,JPG文件的结构包括文件头、数据段、图像数据和文件尾。
数据段是JPG文件最重要的部分,包含了图像的所有信息和压缩后的图像数据。
jpg特点和适用范围

JPG特点和适用范围1. 什么是JPG?JPG(Joint Photographic Experts Group)是一种常见的图像文件格式,也被称为JPEG。
它是一种有损压缩格式,主要用于存储数字图像。
JPG格式通过减少图像中的细节和颜色信息来减小文件的大小,从而实现了高度的压缩比。
2. JPG的特点2.1 高度的压缩比JPG采用有损压缩算法,可以将图像文件的大小大幅度减小。
这是通过降低图像质量、减少颜色深度和丢弃一些细节来实现的。
由于高度的压缩比,JPG成为Web上广泛使用的图像格式之一。
2.2 良好的可视化效果尽管JPG是有损压缩格式,但在适当的设置下,它可以提供良好的可视化效果。
在合理范围内降低图像质量后,人眼难以察觉到细微差别。
因此,对于普通用户而言,使用JPG格式保存图像不会对观看体验产生明显影响。
2.3 支持多种颜色模式JPG支持多种颜色模式,包括灰度图像、索引彩色图像和真彩色图像。
这使得JPG适用于不同类型的图像,例如照片、插图和艺术作品。
2.4 可调节的压缩质量JPG格式允许用户根据需要调整压缩质量。
在保存图像时,可以选择不同的质量级别。
较高的质量级别将产生较大的文件大小,但保留更多细节和颜色信息;而较低的质量级别将产生更小的文件大小,但会导致一些细节损失和可见的压缩伪影。
2.5 兼容性广泛JPG格式是一种非常通用的图像格式,在各种设备和平台上都得到广泛支持。
几乎所有图片查看器、编辑软件和网页浏览器都能够打开和显示JPG文件。
3. JPG适用范围3.1 数字摄影由于JPG能够提供相对较小的文件大小,并且在合理范围内保持良好可视化效果,因此它成为了数字摄影中最常用的图像格式之一。
无论是专业摄影师还是普通用户,在保存照片时通常会选择JPG格式,以便在存储空间和图像质量之间取得平衡。
3.2 网络传输由于JPG文件大小较小,适合网络传输。
在上传图像到互联网时,往往需要考虑带宽和存储限制。
JPEG文件格式简单分析.

摘要:这篇文章大体上介绍了JPEG文件的结构信息以及它的压缩算法和编码方式。
使读者能够对JPEG文件格式有大体上的了解。
为读者进一步进行学习JPEG文件压缩做好准备关键字:十六进制,段格式,编码一、JPEG文件格式概述:图像和动画的存储方式是一个很重要的问题。
幸好我们有了数据压缩,有了JPEG等多种压缩存储图像的文件格式,我们今天才能够拿着小小的一个存储器,却存上许多张色彩鲜艳的图片。
如果没有图像压缩算法,也许我们的多媒体时代就会晚到来许多年。
JPEG图像存储格式一个比较成熟的图像有损压缩格式,虽然一个图片经过转化为JPEG图像后,一些数据会丢失,但是,人眼是很不容易分辨出来这种差别的。
也就是说,JPEG图像存储格式既满足了人眼对色彩和分辨率的要求,又适当的去除了图像中很难被人眼所分辨出的色彩,在图像的清晰与大小中JPEG找到了一个很好的平衡点。
虽然图像转化为JPEG格式会减小很多,但是并不是文件就变得简单了,相反,JPEG文件的格式是比较复杂的。
不经过认真地分析,是不容易弄懂它的。
二、JPEG文件的存储方式:JPEG文件的格式是分为一个一个的段来存储的(但并不是全部都是段),段的多少和长度并不是一定的。
只要包含了足够的信息,该JPEG文件就能够被打开,呈现给人们。
JPEG文件的每个段都一定包含两部分一个是段的标识,它由两个字节构成:第一个字节是十六进制0xFF,第二个字节对于不同的段,这个值是不同的。
紧接着的两个字节存放的是这个段的长度(除了前面的两个字节0xFF和0xXX,X表示不确定。
他们是不算到段的长度中的)。
注意:这个长度的表示方法是按照高位在前,低位在后的,与Intel的表示方法不同。
比方说一个段的长度是0x12AB,那么它会按照0x12,0xAB的顺序存储。
但是如果按照Intel的方式:高位在后,低位在前的方式会存储成0xAB,0x12,而这样的存储方法对于JPEG是不对的。
这样的话如果一个程序不认识JPEG文件某个段,它就可以读取后两个字节,得到这个段的长度,并跳过忽略它。
图像jpg的特点及应用范围

图像jpg的特点及应用范围图像jpg是一种常见的图像文件格式,它具有以下特点:1. 压缩性能好:jpg采用有损压缩算法,可以在保持图像质量的前提下大幅减小文件大小。
这种压缩算法主要通过减少图像中的冗余信息和舍弃人眼难以察觉的细节来实现。
因此,jpg格式适用于需要在保证图像质量的同时减小文件大小的场景。
2. 支持多种色彩模式:jpg格式支持灰度图像、彩色图像和真彩色图像等多种色彩模式。
这使得jpg格式可以适用于不同领域的图像处理需求,如摄影、印刷、艺术设计等。
3. 兼容性强:jpg格式是一种广泛支持的图像文件格式,几乎所有的图像处理软件和设备都能够读取和显示jpg格式的图像。
这使得jpg格式成为了互联网上常见的图像格式之一,方便了图像的传输和共享。
4. 可调节的压缩比:jpg格式允许用户根据需要调节压缩比,以平衡图像质量和文件大小。
较高的压缩比可以减小文件大小,但会导致图像质量的损失;而较低的压缩比可以保持较高的图像质量,但会增加文件大小。
这种可调节的压缩比使得jpg格式适用于不同需求的图像处理任务。
5. 不支持透明度:jpg格式不支持图像的透明度,即无法保存带有透明背景的图像。
这是jpg格式的一个局限性,对于需要保存透明背景的图像,应该选择其他支持透明度的图像格式,如png格式。
图像jpg的应用范围广泛,主要包括以下几个方面:1. 数码摄影:jpg格式是数码相机最常用的图像格式之一。
由于数码相机拍摄的照片通常较大,使用jpg格式可以将照片的文件大小减小,方便存储和传输。
2. 网络传输:jpg格式是互联网上常见的图像格式之一。
由于jpg格式具有较好的压缩性能,可以在保持图像质量的前提下减小文件大小,因此适合在网络上传输和共享图像。
3. 印刷和出版:jpg格式适用于印刷和出版行业。
在印刷过程中,图像需要转换为CMYK色彩模式,而jpg格式可以支持CMYK色彩模式,因此适合用于印刷品的制作。
4. 广告和宣传:jpg格式适用于广告和宣传行业。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
This paper is a revised version of an article by the same title and author which appeared in the April 1991 issue of Communications of the ACM.AbstractFor the past few years, a joint ISO/CCITT committee known as JPEG (Joint Photographic Experts Group) has been working to establish the first international compression standard for continuous-tone still images, both grayscale and color. JPEG’s proposed standard aims to be generic, to support a wide variety of applications for continuous-tone images. To meet the differing needs of many applications, the JPEG standard includes two basic compression methods, each with various modes of operation. A DCT-based method is specified for “lossy’’ compression, and a predictive method for “lossless’’ compression. JPEG features a simple lossy technique known as the Baseline method, a subset of the other DCT-based modes of operation. The Baseline method has been by far the most widely implemented JPEG method to date, and is sufficient in its own right for a large number of applications. This article provides an overview of the JPEG standard, and focuses in detail on the Baseline method.1 IntroductionAdvances over the past decade in many aspects of digital technology - especially devices for image acquisition, data storage, and bitmapped printing and display - have brought about many applications of digital imaging. However, these applications tend to be specialized due to their relatively high cost. With the possible exception of facsimile, digital images are not commonplace in general-purpose computing systems the way text and geometric graphics are. The majority of modern business and consumer usage of photographs and other types of images takes place through more traditional analog means.The key obstacle for many applications is the vast amount of data required to represent a digital image directly. A digitized version of a single, color picture at TV resolution contains on the order of one million bytes; 35mm resolution requires ten times that amount. Use of digital images often is not viable due to high storage or transmission costs, even when image capture and display devices are quite affordable.Modern image compression technology offers a possible solution. State-of-the-art techniques can compress typical images from 1/10 to 1/50 their uncompressed size without visibly affecting image quality. But compression technology alone is not sufficient. For digital image applications involving storage or transmission to become widespread in today’s marketplace, a standard image compression method is needed to enable interoperability of equipment from different manufacturers. The CCITT recommendation for today’s ubiquitous Group 3 fax machines [17] is a dramatic example of how a standard compression method can enable an important image application. The Group 3 method, however, deals with bilevel images only and does not address photographic image compression.For the past few years, a standardization effort known by the acronym JPEG, for Joint Photographic Experts Group, has been working toward establishing the first international digital image compression standard for continuous-tone (multilevel) still images, both grayscale and color. The “joint” in JPEG refers to a collaboration between CCITT and ISO. JPEG convenes officially as the ISO committee designated JTC1/SC2/WG10, but operates in close informal collaboration with CCITT SGVIII. JPEG will be both an ISO Standard and a CCITT Recommendation. The text of both will be identical.Photovideotex, desktop publishing, graphic arts, color facsimile, newspaper wirephoto transmission, medical imaging, and many other continuous-tone image applications require a compression standard in order toThe JPEG Still Picture Compression StandardGregory K. WallaceMultimedia EngineeringDigital Equipment CorporationMaynard, MassachusettsSubmitted in December 1991 for publication in IEEE Transactions on Consumer Electronicsdevelop significantly beyond their present state. JPEG has undertaken the ambitious task of developing ageneral-purpose compression standard to meet the needs of almost all continuous-tone still-image applications.If this goal proves attainable, not only will individual applications flourish, but exchange of images across application boundaries will be facilitated. This latter feature will become increasingly important as more image applications are implemented on general-purpose computing systems, which are themselves becoming increasingly interoperable and internetworked. For applications which require specialized VLSI to meet their compression and decompression speed requirements, a common method will provide economies of scale not possible within a single application.This article gives an overview of JPEG’s proposed image-compression standard. Readers without prior knowledge of JPEG or compression based on the Discrete Cosine Transform (DCT) are encouraged to study first the detailed description of the Baseline sequential codec, which is the basis for all of the DCT-based decoders. While this article provides many details, many more are necessarily omitted. The reader should refer to the ISO draft standard [2] before attempting implementation.Some of the earliest industry attention to the JPEG proposal has been focused on the Baseline sequential codec as a motion image compression method - of the ‘‘intraframe’’ class, where each frame is encoded as a separate image. This class of motion image coding, while providing less compression than ‘‘interframe’’methods like MPEG, has greater flexibility for video editing. While this paper focuses only on JPEG as a still picture standard (as ISO intended), it is interesting to note that JPEG is likely to become a ‘‘de facto’’intraframe motion standard as well.2 Background: Requirements and Selec-tion ProcessJPEG’s goal has been to develop a method for continuous-tone image compression which meets the following requirements:1)be at or near the state of the art with regard tocompression rate and accompanying image fidelity, over a wide range of image quality ratings, and especially in the range where visual fidelity to the original is characterized as “very good” to “excellent”; also, the encoder should be parameterizable, so that the application (or user) can set the desired compression/quality tradeoff;2)be applicable to practically any kind ofcontinuous-tone digital source image (i.e. for most practical purposes not be restricted to images of certain dimensions, color spaces, pixel aspect ratios, etc.) and not be limited to classes of imagery with restrictions on scene content, such as complexity, range of colors, or statistical properties;3)have tractable computational complexity, to makefeasible software implementations with viable performance on a range of CPU’s, as well as hardware implementations with viable cost for applications requiring high performance;4) have the following modes of operation:•Sequential encoding: each image component is encoded in a single left-to-right, top-to-bottomscan;•Progressive encoding: the image is encoded in multiple scans for applications in whichtransmission time is long, and the viewerprefers to watch the image build up in multiplecoarse-to-clear passes;•Lossless encoding: the image is encoded to guarantee exact recovery of every sourceimage sample value (even though the result islow compression compared to the lossymodes);•Hierarchical encoding: the image is encoded at multiple resolutions so that lower-resolutionversions may be accessed without first havingto decompress the image at its full resolution. In June 1987, JPEG conducted a selection process based on a blind assessment of subjective picture quality, and narrowed 12 proposed methods to three. Three informal working groups formed to refine them, and in January 1988, a second, more rigorous selection process [19] revealed that the “ADCT” proposal [11], based on the 8x8 DCT, had produced the best picture quality.At the time of its selection, the DCT-based method was only partially defined for some of the modes of operation. From 1988 through 1990, JPEG undertook the sizable task of defining, documenting, simulating, testing, validating, and simply agreeing on the plethora of details necessary for genuine interoperability and universality. Further history of the JPEG effort is contained in [6, 7, 9, 18].3 Architecture of the Proposed Standard The proposed standard contains the four “modes of operation” identified previously. For each mode, one or more distinct codecs are specified. Codecs within a mode differ according to the precision of source image samples they can handle or the entropy coding method they use. Although the word codec (encoder/decoder) is used frequently in this article, there is no requirement that implementations must include both an encoder and a decoder. Many applications will have systems or devices which require only one or the other.The four modes of operation and their various codecs have resulted from JPEG’s goal of being generic and from the diversity of image formats across applications. The multiple pieces can give the impression of undesirable complexity, but they should actually be regarded as a comprehensive “toolkit” which can span a wide range of continuous-tone image applications. It is unlikely that many implementations will utilize every tool -- indeed, most of the early implementations now on the market (even before final ISO approval) have implemented only the Baseline sequential codec.The Baseline sequential codec is inherently a rich and sophisticated compression method which will be sufficient for many applications. Getting this minimum JPEG capability implemented properly and interoperably will provide the industry with an important initial capability for exchange of images across vendors and applications.4 Processing Steps for DCT-Based Coding Figures 1 and 2 show the key processing steps which are the heart of the DCT-based modes of operation. These figures illustrate the special case of single-component (grayscale) image compression. The reader can grasp the essentials of DCT-based compression by thinking of it as essentially compression of a stream of 8x8 blocks of grayscale image samples. Color image compression can then be approximately regarded as compression of multiple grayscale images, which are either compressed entirely one at a time, or are compressed by alternately interleaving 8x8 sample blocks from each in turn.For DCT sequential-mode codecs, which include the Baseline sequential codec, the simplified diagrams indicate how single-component compression works in a fairly complete way. Each 8x8 block is input, makes its way through each processing step, and yields output in compressed form into the data stream. For DCT progressive-mode codecs, an image buffer exists prior to the entropy coding step, so that an image can be stored and then parceled out in multiple scans with suc-cessively improving quality. For the hierarchical mode of operation, the steps shown are used as building blocks within a larger framework.4.1 8x8 FDCT and IDCTAt the input to the encoder, source image samples are grouped into 8x8 blocks, shifted from unsigned integers with range [0, 2P - 1] to signed integers with range [-2P-1, 2P-1-1], and input to the Forward DCT (FDCT). At the output from the decoder, the Inverse DCT (IDCT) outputs 8x8 sample blocks to form the reconstructed image. The following equations are the idealized mathematical definitions of the 8x8 FDCT and 8x8 IDCT:The DCT is related to the Discrete Fourier Transform (DFT). Some simple intuition for DCT-based compression can be obtained by viewing the FDCT as a harmonic analyzer and the IDCT as a harmonic synthesizer. Each 8x8 block of source image samples is effectively a 64-point discrete signal which is a function of the two spatial dimensions x and y. The FDCT takes such a signal as its input and decomposes it into 64 orthogonal basis signals. Each contains one of the 64 unique two-dimensional (2D) “spatial frequencies’’ which comprise the input signal’s “spectrum.” The ouput of the FDCT is the set of 64 basis-signal amplitudes or “DCT coefficients” whose values are uniquely determined by the particular 64-point input signal.The DCT coefficient values can thus be regarded as the relative amount of the 2D spatial frequencies contained in the 64-point input signal. The coefficient with zero frequency in both dimensions is called the “DC coefficient” and the remaining 63 coefficients are called the “AC coefficients.’’ Because sample values[F(u,v)=14C(u)C(v)7x=07y=0f(x,y)*cos(2x+1)uπ16cos(2x+1)vπ16](1)[f(x,y)=147u=07v=0C(u)C(v)F(u,v)*cos(2x+1)uπ16cos(2x+1)vπ16](2) where:forotherwise.C(u),C(v)=1 2√u,C(u),C(v)=1v=;0typically vary slowly from point to point across an image, the FDCT processing step lays the foundation for achieving data compression by concentrating most of the signal in the lower spatial frequencies. For a typical 8x8 sample block from a typical source image,most of the spatial frequencies have zero or near-zero amplitude and need not be encoded.At the decoder the IDCT reverses this processing step. It takes the 64 DCT coefficients (which at that point have been quantized) and reconstructs a 64-point ouput image signal by summing the basis signals. Mathematically, the DCT is one-to-one mapping for 64-point vectors between the image and the frequency domains. If the FDCT and IDCT could be computed with perfect accuracy and if the DCT coefficients were not quantized as in the following description, the original 64-point signal could be exactly recovered. In principle, the DCT introduces no loss to the source image samples; it merely transforms them to a domain in which they can be more efficiently encoded.Some properties of practical FDCT and IDCT implementations raise the issue of what precisely should be required by the JPEG standard. A fundamental property is that the FDCT and IDCT equations contain transcendental functions. Consequently, no physical implementation can compute them with perfect accuracy. Because of the DCT’s application importance and its relationship to the DFT, many different algorithms by which theFDCT and IDCT may be approximately computed have been devised [16]. Indeed, research in fast DCT algorithms is ongoing and no single algorithm is optimal for all implementations. What is optimal in software for a general-purpose CPU is unlikely to be optimal in firmware for a programmable DSP and is certain to be suboptimal for dedicated VLSI.Even in light of the finite precision of the DCT inputs and outputs, independently designed implementations of the very same FDCT or IDCT algorithm which differ even minutely in the precision by which they represent cosine terms or intermediate results, or in the way they sum and round fractional values, will eventually produce slightly different outputs from identical inputs.To preserve freedom for innovation and customization within implementations, JPEG has chosen to specify neither a unique FDCT algorithm or a unique IDCT algorithm in its proposed standard. This makes compliance somewhat more difficult to confirm,because two compliant encoders (or decoders)generally will not produce identical outputs given identical inputs. The JPEG standard will address this issue by specifying an accuracy test as part of its compliance tests for all DCT-based encoders and decoders; this is to ensure against crudely inaccurate cosine basis functions which would degrade image quality.EntropyDecoderDequantizer IDCTDCT-Based DecoderTable Table Specifications Specifications Compressed Image Data Reconstructed Image DataFigure 1. DCT-Based Encoder Processing StepsFigure 2. DCT-Based Decoder Processing StepsFor each DCT-based mode of operation, the JPEG proposal specifies separate codecs for images with 8-bit and 12-bit (per component) source image samples. The 12-bit codecs, needed to accommodate certain types of medical and other images, require greater computational resources to achieve the required FDCT or IDCT accuracy. Images with other sample precisions can usually be accommodated by either an 8-bit or 12-bit codec, but this must be done outside the JPEG standard. For example, it would be the responsibility of an application to decide how to fit or pad a 6-bit sample into the 8-bit encoder’s input interface, how to unpack it at the decoder’s output, and how to encode any necessary related information.4.2 QuantizationAfter output from the FDCT, each of the 64 DCT coefficients is uniformly quantized in conjunction with a 64-element Quantization Table, which must be specified by the application (or user) as an input to the encoder. Each element can be any integer value from 1to 255, which specifies the step size of the quantizer for its corresponding DCT coefficient. The purpose of quantization is to achieve further compression by representing DCT coefficients with no greater precision than is necessary to achieve the desired image quality. Stated another way, the goal of this processing step is to discard information which is not visually significant.Quantization is a many-to-one mapping, and therefore is fundamentally lossy. It is the principal source of lossiness in DCT-based encoders.Quantization is defined as division of each DCT coefficient by its corresponding quantizer step size,followed by rounding to the nearest integer:F Q (u ,v ) = Integer Round ( F (u ,v )Q (u ,v) )(3)This output value is normalized by the quantizer step size. Dequantization is the inverse function, which in this case means simply that the normalization is removed by multiplying by the step size, which returns the result to a representation appropriate for input to the IDCT:When the aim is to compress the image as much as possible without visible artifacts, each step size ideally should be chosen as the perceptual threshold or “just noticeable difference” for the visual contribution of its corresponding cosine basis function. These thresholds are also functions of the source image characteristics,display characteristics and viewing distance. For applications in which these variables can be reasonably well defined, psychovisual experiments can be performed to determine the best thresholds. The experiment described in [12] has led to a set of Quantization Tables for CCIR-601 [4] images and displays. These have been used experimentally by JPEG members and will appear in the ISO standard as a matter of information, but not as a requirement.4.3 DC Coding and Zig-Zag SequenceAfter quantization, the DC coefficient is treated separately from the 63 AC coefficients. The DC coefficient is a measure of the average value of the 64image samples. Because there is usually strong correlation between the DC coefficients of adjacent 8x8blocks, the quantized DC coefficient is encoded as the difference from the DC term of the previous block in the encoding order (defined in the following), as shown in Figure 3. This special treatment is worthwhile, as DC coefficients frequently contain a significant fraction of the total image energy.F Q (u ,v ) =F Q(u ,v )Q (u ,v )*(4). . .DIFF = DC i - DC i-1i-1iDifferential DC encoding Zig−zag sequence. . .770770Figure 3. Preparation of Quantized Coefficients for Entropy CodingFinally, all of the quantized coefficients are ordered into the “zig-zag” sequence, also shown in Figure 3. This ordering helps to facilitate entropy coding by placing low-frequency coefficients (which are more likely to be nonzero) before high-frequency coefficients.4.4 Entropy CodingThe final DCT-based encoder processing step is entropy coding. This step achieves additional compression losslessly by encoding the quantized DCT coefficients more compactly based on their statistical characteristics. The JPEG proposal specifies two entropy coding methods - Huffman coding [8] and arithmetic coding [15]. The Baseline sequential codec uses Huffman coding, but codecs with both methods are specified for all modes of operation.It is useful to consider entropy coding as a 2-step process. The first step converts the zig-zag sequence of quantized coefficients into an intermediate sequence of symbols. The second step converts the symbols to a data stream in which the symbols no longer have externally identifiable boundaries. The form and definition of the intermediate symbols is dependent on both the DCT-based mode of operation and the entropy coding method.Huffman coding requires that one or more sets of Huffman code tables be specified by the application. The same tables used to compress an image are needed to decompress it. Huffman tables may be predefined and used within an application as defaults, or computed specifically for a given image in an initial statistics-gathering pass prior to compression. Such choices are the business of the applications which use JPEG; the JPEG proposal specifies no required Huffman tables. Huffman coding for the Baseline sequential encoder is described in detail in section 7.By contrast, the particular arithmetic coding method specified in the JPEG proposal [2] requires no tables to be externally input, because it is able to adapt to the image statistics as it encodes the image. (If desired, statistical conditioning tables can be used as inputs for slightly better efficiency, but this is not required.) Arithmetic coding has produced 5-10% better compression than Huffman for many of the images which JPEG members have tested. However, some feel it is more complex than Huffman coding for certain implementations, for example, the highest-speed hardware implementations. (Throughout JPEG’s history, “complexity” has proved to be most elusive as a practical metric for comparing compression methods.) If the only difference between two JPEG codecs is the entropy coding method, transcoding between the two is possible by simply entropy decoding with one method and entropy recoding with the other.4.5 Compression and Picture QualityFor color images with moderately complex scenes, all DCT-based modes of operation typically produce the following levels of picture quality for the indicated ranges of compression. These levels are only a guideline - quality and compression can vary significantly according to source image characteristics and scene content. (The units “bits/pixel” here mean the total number of bits in the compressed image -including the chrominance components - divided by the number of samples in the luminance component.)•0.25-0.5 bits/pixel: moderate to good quality, sufficient for some applications;•0.5-0.75 bits/pixel: good to very good quality, sufficient for many applications;•0.75-1/5 bits/pixel: excellent quality, sufficient for most applications;• 1.5-2.0 bits/pixel: usually indistinguishable from the original, sufficient for the most demanding applications.5 Processing Steps for Predictive Lossless CodingAfter its selection of a DCT-based method in 1988, JPEG discovered that a DCT-based lossless mode was difficult to define as a practical standard against which encoders and decoders could be independently implemented, without placing severe constraints on both encoder and decoder implementations.JPEG, to meet its requirement for a lossless mode of operation, has chosen a simple predictive method which is wholly independent of the DCT processing described previously. Selection of this method was not the result of rigorous competitive evaluation as was the DCT-based method. Nevertheless, the JPEG lossless method produces results which, in light of its simplicity, are surprisingly close to the state of the art for lossless continuous-tone compression, as indicated by a recent technical report [5].Figure 4 shows the main processing steps for a single-component image. A predictor combines the values of up to three neighboring samples (A, B, and C) to form a prediction of the sample indicated by X in Figure 5. This prediction is then subtracted from the actual value of sample X, and the difference is encodedlosslessly by either of the entropy coding methods -Huffman or arithmetic. Any one of the eight predictors listed in Table 1 (under “selection-value”) can be used.Selections 1, 2, and 3 are one-dimensional predictors and selections 4, 5, 6 and 7 are two-dimensional predictors. Selection-value 0 can only be used for differential coding in the hierarchical mode of operation. The entropy coding is nearly identical to that used for the DC coefficient as described in section 7.1 (for Huffman coding).For the lossless mode of operation, two different codecs are specified - one for each entropy coding method. The encoders can use any source image precision from 2 to 16 bits/sample, and can use any of the predictors except selection-value 0. The decoders must handle any of the sample precisions and any of the predictors. Lossless codecs typically produce around 2:1compression for color images with moderately complex scenes.Figure 5. 3-Sample Prediction Neighborhood C B A X6 Multiple-Component ImagesThe previous sections discussed the key processing steps of the DCT-based and predictive lossless codecs for the case of single-component source images. These steps accomplish the image data compression. But a good deal of the JPEG proposal is also concerned with the handling and control of color (or other) images with multiple components. JPEG’s aim for a generic compression standard requires its proposal to accommodate a variety of source image formats.6.1 Source Image FormatsThe source image model used in the JPEG proposal is an abstraction from a variety of image types and applications and consists of only what is necessary to compress and reconstruct digital image data. The reader should recognize that the JPEG compressed data format does not encode enough information to serve as a complete image representation. For example, JPEG does not specify or encode any information on pixel aspect ratio, color space, or image acquisition characteristics.Table 1. Predictors for Lossless Codingselection-valueprediction 0no prediction 1234567A B CA+B-CA+((B-C)/2)B+((A-C)/2)(A+B)/2PredictorEntropy EncoderLossless EncoderSource Image DataTable SpecificationsCompressed Image DataFigure 4. Lossless Mode Encoder Processing StepsFigure 6 illustrates the JPEG source image model. A source image contains from 1 to 255 image components, sometimes called color or spectral bands or channels. Each component consists of a rectangular array of samples. A sample is defined to be an unsigned integer with precision P bits, with any value in the range [0, 2P -1]. All samples of all components within the same source image must have the same precision P. P can be 8 or 12 for DCT-based codecs,and 2 to 16 for predictive codecs.The ith component has sample dimensions x i by y i . To accommodate formats in which some image components are sampled at different rates than others,components can have different dimensions. The dimensions must have a mutual integral relationship defined by H i and V i , the relative horizontal and vertical sampling factors, which must be specified for each component. Overall image dimensions X and Y are defined as the maximum x i and y i for all components in the image, and can be any number up to 216. H and V are allowed only the integer values 1through 4. The encoded parameters are X, Y, and H i s and V i s for each components. The decoder reconstructs the dimensions x i and y i for each component, according to the following relationship shown in Equation 5:where is the ceiling function.6.2 Encoding Order and InterleavingA practical image compression standard must address how systems will need to handle the data during the process of decompression. Many applications need to pipeline the process of displaying or printing multiple-component images in parallel with the processx i = X H i H andy i =Y V i V maxm ax ××(5)of decompression. For many systems, this is onlyfeasible if the components are interleaved together within the compressed data stream.To make the same interleaving machinery applicable to both DCT-based and predictive codecs, the JPEG proposal has defined the concept of “data unit.” A data unit is a sample in predictive codecs and an 8x8 block of samples in DCT-based codecs.The order in which compressed data units are placed in the compressed data stream is a generalization of raster-scan order. Generally, data units are ordered from left-to-right and top-to-bottom according to the orientation shown in Figure 6. (It is the responsibility of applications to define which edges of a source image are top, bottom, left and right.) If an image component is noninterleaved (i.e., compressed without being interleaved with other components), compressed data units are ordered in a pure raster scan as shown in Figure 7.When two or more components are interleaved, each component C i is partitioned into rectangular regions of H i by V i data units, as shown in the generalized example of Figure 8. Regions are ordered within a component from left-to-right and top-to-bottom, and within a region, data units are ordered from left-to-right and top-to-bottom. The JPEG proposal defines the term Minimum Coded Unit (MCU) to be the smallestright bottomleftFigure 7. Noninterleaved Data Orderingtopline(a) Source image with multiple components C Figure 6. JPEG Source Image Model(b) Characteristics of an image componentC Nf。