小张学算法之音视频算法:2.jpeg图像压缩算法
接着上节视频压缩算法,今天来看看静态图像的压缩,相比视频压缩,图片压缩就太简单啦,let‘s go!!
jepg文件二进制格式
jpeg二进制文件分块表
分块标识 | 值 | 涵义 |
---|---|---|
SOI | ff d8 | 文件开始 |
APP0 | ff e0 | 定义交换格式和图像识别信息 |
DQT | ff db | 定义量化表 |
SOF0 | ff c0 | 帧开始 |
DHT | ff c4 | 霍夫曼(Huffman)表 |
SOS | ff da | 扫描行开始 |
EOI | ff d9 | 文件结束 |
jpeg文件是由0xffd8开头的,代表着文件的开头。
可以看到文件头信息,其实最重要的就是两张表了,量化表和huffman表,存储图像的压缩信息,至于文件的交换格式和图像识别信息就没什么特别的。
详细头部快信息见https://blog.csdn.net/sinat_26472165/article/details/85342766
jpeg的压缩过程,
1.先分块88或1616的块,进行DCT变换到频域;
2. 进行量化操作,去掉高频分量;
3. Z型扫描,
4. 进行熵编码:huffman编码。
量化表有两张:亮度量化表,色度量化表。
huffman表有亮度AC(交流)、亮度DC(直流)、色度AC、色度DC,四张huffman表;
jpeg中存储的是yCrCb色彩空间的数据,也就是yuv数据。使用jpeg_snoop工具查看下jpeg头信息;
JPEGsnoop 1.8.0 by Calvin Hasshttp://www.impulseadventure.com/photo/-------------------------------------Filename: [C:\Users\IBM\Pictures\Camera Roll\0.jpg]Filesize: [23643] BytesStart Offset: 0x00000000
*** Marker: SOI (xFFD8) ***OFFSET: 0x00000000 *** Marker: APP0 (xFFE0) *** /*数据交换信息*/OFFSET: 0x00000002Length = 16 /*交换数据长度*/Identifier = [JFIF] /*交换格式*/version = [1.1] /*版本*/density = 1 x 1 (aspect ratio)thumbnail = 0 x 0*** Marker: DQT (xFFDB) *** /*量化表*/Define a Quantization Table.OFFSET: 0x00000014Table length = 67----Precision=8 bitsDestination ID=0 (Luminance) /*灰度量化表*/DQT, Row #0: 2 1 1 2 2 4 5 6 DQT, Row #1: 1 1 1 2 3 6 6 6 DQT, Row #2: 1 1 2 2 4 6 7 6 DQT, Row #3: 1 2 2 3 5 9 8 6 DQT, Row #4: 2 2 4 6 7 11 10 8 DQT, Row #5: 2 4 6 6 8 10 11 9 DQT, Row #6: 5 6 8 9 10 12 12 10 DQT, Row #7: 7 9 10 10 11 10 10 10 Approx quality factor = 95.04 (scaling=9.93 variance=1.25)*** Marker: DQT (xFFDB) ***Define a Quantization Table.OFFSET: 0x00000059Table length = 67----Precision=8 bitsDestination ID=1 (Chrominance) /*色度量化表*/DQT, Row #0: 2 2 2 5 10 10 10 10 DQT, Row #1: 2 2 3 7 10 10 10 10 DQT, Row #2: 2 3 6 10 10 10 10 10 DQT, Row #3: 5 7 10 10 10 10 10 10 DQT, Row #4: 10 10 10 10 10 10 10 10 DQT, Row #5: 10 10 10 10 10 10 10 10 DQT, Row #6: 10 10 10 10 10 10 10 10 DQT, Row #7: 10 10 10 10 10 10 10 10 Approx quality factor = 94.91 (scaling=10.18 variance=0.26)*** Marker: SOF0 (Baseline DCT) (xFFC0) ***OFFSET: 0x0000009EFrame header length = 17Precision = 8Number of Lines = 180Samples per Line = 320Image Size = 320 x 180Raw Image Orientation = LandscapeNumber of Img components = 3 /*组件数yCrCb,所以是3*/Component[1]: ID=0x01, Samp Fac=0x22 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y) /*使用灰度量化表进行量化*/Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cb) /*使用色度量化表进行量化*/Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cr) /*使用色度量化表进行量化*/*** Marker: DHT (Define Huffman Table) (xFFC4) ***OFFSET: 0x000000B1Huffman table length = 31----Destination ID = 0Class = 0 (DC / Lossless Table) /*霍夫曼表,灰度的直流分量*/Codes of length 01 bits (000 total): Codes of length 02 bits (001 total): 00 Codes of length 03 bits (005 total): 01 02 03 04 05 Codes of length 04 bits (001 total): 06 Codes of length 05 bits (001 total): 07 Codes of length 06 bits (001 total): 08 Codes of length 07 bits (001 total): 09 Codes of length 08 bits (001 total): 0A Codes of length 09 bits (001 total): 0B Codes of length 10 bits (000 total): Codes of length 11 bits (000 total): Codes of length 12 bits (000 total): Codes of length 13 bits (000 total): Codes of length 14 bits (000 total): Codes of length 15 bits (000 total): Codes of length 16 bits (000 total): Total number of codes: 012*** Marker: DHT (Define Huffman Table) (xFFC4) ***OFFSET: 0x000000D2Huffman table length = 181----Destination ID = 0Class = 1 (AC Table) /*霍夫曼表,灰度的交流分量*/Codes of length 01 bits (000 total): Codes of length 02 bits (002 total): 01 02 Codes of length 03 bits (001 total): 03 Codes of length 04 bits (003 total): 00 04 11 Codes of length 05 bits (003 total): 05 12 21 Codes of length 06 bits (002 total): 31 41 Codes of length 07 bits (004 total): 06 13 51 61 Codes of length 08 bits (003 total): 07 22 71 Codes of length 09 bits (005 total): 14 32 81 91 A1 Codes of length 10 bits (005 total): 08 23 42 B1 C1 Codes of length 11 bits (004 total): 15 52 D1 F0 Codes of length 12 bits (004 total): 24 33 62 72 Codes of length 13 bits (000 total): Codes of length 14 bits (000 total): Codes of length 15 bits (001 total): 82 Codes of length 16 bits (125 total): 09 0A 16 17 18 19 1A 25 26 27 28 29 2A 34 35 36 37 38 39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 83 84 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 D8 D9 DA E1 E2 E3 E4 E5 E6 E7 E8 E9 EA F1 F2 F3 F4 F5 F6 F7 F8 F9 FA Total number of codes: 162*** Marker: DHT (Define Huffman Table) (xFFC4) ***OFFSET: 0x00000189Huffman table length = 31----Destination ID = 1Class = 0 (DC / Lossless Table) /*霍夫曼表,色度的直流分量*/Codes of length 01 bits (000 total): Codes of length 02 bits (003 total): 00 01 02 Codes of length 03 bits (001 total): 03 Codes of length 04 bits (001 total): 04 Codes of length 05 bits (001 total): 05 Codes of length 06 bits (001 total): 06 Codes of length 07 bits (001 total): 07 Codes of length 08 bits (001 total): 08 Codes of length 09 bits (001 total): 09 Codes of length 10 bits (001 total): 0A Codes of length 11 bits (001 total): 0B Codes of length 12 bits (000 total): Codes of length 13 bits (000 total): Codes of length 14 bits (000 total): Codes of length 15 bits (000 total): Codes of length 16 bits (000 total): Total number of codes: 012*** Marker: DHT (Define Huffman Table) (xFFC4) ***OFFSET: 0x000001AAHuffman table length = 181----Destination ID = 1Class = 1 (AC Table) /*霍夫曼表,色度的交流分量*/Codes of length 01 bits (000 total): Codes of length 02 bits (002 total): 00 01 Codes of length 03 bits (001 total): 02 Codes of length 04 bits (002 total): 03 11 Codes of length 05 bits (004 total): 04 05 21 31 Codes of length 06 bits (004 total): 06 12 41 51 Codes of length 07 bits (003 total): 07 61 71 Codes of length 08 bits (004 total): 13 22 32 81 Codes of length 09 bits (007 total): 08 14 42 91 A1 B1 C1 Codes of length 10 bits (005 total): 09 23 33 52 F0 Codes of length 11 bits (004 total): 15 62 72 D1 Codes of length 12 bits (004 total): 0A 16 24 34 Codes of length 13 bits (000 total): Codes of length 14 bits (001 total): E1 Codes of length 15 bits (002 total): 25 F1 Codes of length 16 bits (119 total): 17 18 19 1A 26 27 28 29 2A 35 36 37 38 39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 82 83 84 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 D8 D9 DA E2 E3 E4 E5 E6 E7 E8 E9 EA F2 F3 F4 F5 F6 F7 F8 F9 FA Total number of codes: 162*** Marker: SOS (Start of Scan) (xFFDA) ***OFFSET: 0x00000261Scan header length = 12Number of img components = 3Component[1]: selector=0x01, table=0(DC),0(AC) /*组件1,即y分量,选择hufman表0*/Component[2]: selector=0x02, table=1(DC),1(AC) /*组件2,即Cb分量,选择hufman表1*/Component[3]: selector=0x03, table=1(DC),1(AC) /*组件3,即Cr分量,选择hufman表1*/Spectral selection = 0 .. 63Successive approximation = 0x00/帧数据信息/
*** Decoding SCAN Data ***OFFSET: 0x0000026FScan Decode Mode: No IDCT (DC only)NOTE: Low-resolution DC component shown. Can decode full-res with [Options->Scan Segment->Full IDCT]Scan Data encountered marker 0xFFD9 @ 0x00005C59.0Compression stats:Compression Ratio: 7.51:1 /*压缩比*/Bits per pixel: 3.20:1 /*每个像素占比3.20位*/Huffman code histogram stats: /*huffman编码的直方图统计,因为霍夫曼编码得实现知道没有每个字节数字出现的频次*/Huffman Table: (Dest ID: 0, Class: DC)# codes of length 01 bits: 0 ( 0%)# codes of length 02 bits: 50 ( 5%)# codes of length 03 bits: 426 ( 44%)# codes of length 04 bits: 170 ( 18%)# codes of length 05 bits: 187 ( 19%)# codes of length 06 bits: 111 ( 12%)# codes of length 07 bits: 16 ( 2%)# codes of length 08 bits: 0 ( 0%)# codes of length 09 bits: 0 ( 0%)# codes of length 10 bits: 0 ( 0%)# codes of length 11 bits: 0 ( 0%)# codes of length 12 bits: 0 ( 0%)# codes of length 13 bits: 0 ( 0%)# codes of length 14 bits: 0 ( 0%)# codes of length 15 bits: 0 ( 0%)# codes of length 16 bits: 0 ( 0%)Huffman Table: (Dest ID: 1, Class: DC)# codes of length 01 bits: 0 ( 0%)# codes of length 02 bits: 49 ( 10%)# codes of length 03 bits: 49 ( 10%)# codes of length 04 bits: 91 ( 19%)# codes of length 05 bits: 101 ( 21%)# codes of length 06 bits: 96 ( 20%)# codes of length 07 bits: 70 ( 15%)# codes of length 08 bits: 20 ( 4%)# codes of length 09 bits: 4 ( 1%)# codes of length 10 bits: 0 ( 0%)# codes of length 11 bits: 0 ( 0%)# codes of length 12 bits: 0 ( 0%)# codes of length 13 bits: 0 ( 0%)# codes of length 14 bits: 0 ( 0%)# codes of length 15 bits: 0 ( 0%)# codes of length 16 bits: 0 ( 0%)Huffman Table: (Dest ID: 0, Class: AC)# codes of length 01 bits: 0 ( 0%)# codes of length 02 bits: 12107 ( 46%)# codes of length 03 bits: 3396 ( 13%)# codes of length 04 bits: 4828 ( 18%)# codes of length 05 bits: 2883 ( 11%)# codes of length 06 bits: 675 ( 3%)# codes of length 07 bits: 1210 ( 5%)# codes of length 08 bits: 598 ( 2%)# codes of length 09 bits: 276 ( 1%)# codes of length 10 bits: 207 ( 1%)# codes of length 11 bits: 46 ( 0%)# codes of length 12 bits: 26 ( 0%)# codes of length 13 bits: 0 ( 0%)# codes of length 14 bits: 0 ( 0%)# codes of length 15 bits: 9 ( 0%)# codes of length 16 bits: 65 ( 0%)Huffman Table: (Dest ID: 1, Class: AC)# codes of length 01 bits: 0 ( 0%)# codes of length 02 bits: 1502 ( 38%)# codes of length 03 bits: 687 ( 17%)# codes of length 04 bits: 777 ( 20%)# codes of length 05 bits: 616 ( 16%)# codes of length 06 bits: 218 ( 5%)# codes of length 07 bits: 35 ( 1%)# codes of length 08 bits: 78 ( 2%)# codes of length 09 bits: 28 ( 1%)# codes of length 10 bits: 8 ( 0%)# codes of length 11 bits: 8 ( 0%)# codes of length 12 bits: 4 ( 0%)# codes of length 13 bits: 0 ( 0%)# codes of length 14 bits: 1 ( 0%)# codes of length 15 bits: 1 ( 0%)# codes of length 16 bits: 2 ( 0%)YCC clipping in DC:Y component: [<0= 0] [>255= 0]Cb component: [<0= 0] [>255= 0]Cr component: [<0= 0] [>255= 0]RGB clipping in DC:R component: [<0= 0] [>255= 0]G component: [<0= 0] [>255= 0]B component: [<0= 0] [>255= 0]Average Pixel Luminance (Y):Y=[ 57] (range: 0..255)Brightest Pixel Search:YCC=[ 316, 8, 104] RGB=[185,157,168] @ MCU[ 13, 4]Finished Decoding SCAN DataNumber of RESTART markers decoded: 0Next position in scan buffer: Offset 0x00005C58.4*** Marker: EOI (End of Image) (xFFD9) ***OFFSET: 0x00005C59*** Searching Compression Signatures ***Signature: 01E764F3ECB6C14A51FF83F1FF6D546BSignature (Rotated): 01E6610D026E8E6FE4BECEA9B3328A63File Offset: 0 bytesChroma subsampling: 2x2EXIF Make/Model: NONEEXIF Makernotes: NONEEXIF Software: NONESearching Compression Signatures: (3347 built-in, 0 user(*) )EXIF.Make / Software EXIF.Model Quality Subsamp Match?------------------------- ----------------------------------- ---------------- --------------CAM:[Minolta Co., Ltd. ] [DiMAGE F100 ] [ ] No CAM:[NIKON ] [E2500 ] [FINE ] No CAM:[NIKON ] [E4500 ] [FINE ] No CAM:[NIKON ] [E5400 ] [FINE ] No CAM:[NIKON ] [E5700 ] [FINE ] No CAM:[NIKON ] [E775 ] [FINE ] No CAM:[NIKON ] [E8700 ] [FINE ] No CAM:[OLYMPUS CORPORATION ] [C8080WZ ] [ ] No CAM:[PENTAX ] [PENTAX K10D ] [ ] No CAM:[SAMSUNG TECHWIN ] [Pro 815 ] [ ] No CAM:[SAMSUNG TECHWIN ] [VLUU NV 7, NV 7 ] [ ] No CAM:[SAMSUNG TECHWIN ] [VLUU NV10, NV10 ] [ ] No CAM:[SEIKO EPSON CORP. ] [PhotoPC 3000Z ] [ ] No CAM:[SONY ] [DSC-F828 ] [ ] No CAM:[SONY ] [DSC-H1 ] [ ] No CAM:[SONY ] [DSC-H2 ] [ ] No CAM:[SONY ] [DSC-H5 ] [ ] No CAM:[SONY ] [DSC-H7 ] [ ] No CAM:[SONY ] [DSC-H9 ] [ ] No CAM:[SONY ] [DSC-L1 ] [ ] No CAM:[SONY ] [DSC-N1 ] [ ] No CAM:[SONY ] [DSC-P150 ] [ ] No CAM:[SONY ] [DSC-P200 ] [ ] No CAM:[SONY ] [DSC-S90 ] [ ] No CAM:[SONY ] [DSC-V3 ] [ ] No CAM:[SONY ] [DSC-W55 ] [ ] No CAM:[SONY ] [DSC-W7 ] [ ] No SW :[Apple ImageIO.framework ] [084 ] SW :[IJG Library ] [095 ] The following IJG-based editors also match this signature:SW :[GIMP ] [095 ] SW :[IrfanView ] [095 ] SW :[idImager ] [095 ] SW :[FastStone Image Viewer ] [095 ] SW :[NeatImage ] [095 ] SW :[Paint.NET ] [095 ] SW :[Photomatix ] [095 ] SW :[XnView ] [095 ] Based on the analysis of compression characteristics and EXIF metadata:ASSESSMENT: Class 1 - Image is processed/editedThis may be a new software editor for the database.If this file is processed, and editor doesn't appear in list above,PLEASE ADD TO DATABASE with [Tools->Add Camera to DB]
huffman表的生成可以看
https://www.xuebuyuan.com/1276291.html
libjpeg代码分析
一起来读一读libjpeg中编码部分的实现。源码来自libjpeg-9。
未完待续。。。
小张学算法之音视频算法:2.jpeg图像压缩算法相关推荐
- 音视频算法在淘宝中的应用
近年来,内容业务在行业蓬勃发展.淘宝也在积极进行内容化转型,本次LiveVideoStackCon 2021 上海站大会我们邀请到了阿里巴巴淘系技术高级算法专家--王立波(庄恕),回顾淘宝从图文到短视 ...
- 名校大厂 AI 高手云集,芒果 TV 音视频算法大赛硕果累累
东京奥运会已正式开幕,最新的IT技术也在进入奥运赛场. 本届奥运会引入的 AI 辅助打分,扮演了"助理裁判"的角色.这项技术可以追踪选手动作并实时转换为三维立体图像,再由系统根据图 ...
- 首届“马栏山杯”国际音视频算法优化大赛 马栏山上绽放智能之花
9月8日下午,首届"马栏山杯"国际音视频算法优化大赛颁奖盛典暨高峰论坛在马栏山举行.该活动是2020互联网岳麓峰会的重要组成部分. 前沿课题源自业界需求 马栏山视频文创产业园聚集了 ...
- 首届“马栏山杯”国际音视频算法优化大赛颁奖盛典暨高峰论坛圆满落幕
"音画密码,神机妙算",2020互联网岳麓峰会重磅活动--首届"马栏山杯"国际音视频算法优化大赛颁奖盛典暨高峰论坛9月8日在长沙马栏山盛大举行,湖南省委常委.省 ...
- 年度最Hot,三大热点赛题,首届「马栏山」杯国际音视频算法大赛正式开赛
不久之前,一段使用人工智能修复老北京影像的视频火爆全网,引起了极大的关注.这段修复视频,让我们无须穿越,就能体验一把 100 年前的老北京生活. 在这段效果惊艳的修复视频背后,用到了多项前沿研究,如基 ...
- @开发者,第二届马栏山杯国际音视频算法大赛高分攻略请查收,心动大奖等你来战!...
一秒让墙上的广告消失,保留完整墙面:户外大屏幕显示LOGO被擦除后,背景毫不违和-- 欢迎来到魔法世界-- 停!这其实并不是什么魔法,而是由弗吉尼亚理工大学提出的基于流的视频补全算法FGVC的一项应用 ...
- @开发者,第二届“马栏山”杯国际音视频算法大赛高分攻略请查收,心动大奖等你来战!...
一秒让墙上的广告消失,保留完整墙面:户外大屏幕显示LOGO被擦除后,背景毫不违和-- 欢迎来到魔法世界-- 停!这其实并不是什么魔法,而是由弗吉尼亚理工大学提出的基于流的视频补全算法FGVC的一项应用 ...
- 总奖池120万!中国“马栏山”杯国际音视频算法大赛启动
由中国(长沙)马栏山视频文创产业园和芒果TV联合举办的首届"马栏山"杯国际音视频算法大赛,以搭建专业技术交流平台,遴选杰出算法人才为目的,面向全社会及高等院校.科研单位.互联网企业 ...
- 千亿企业的真实业务思考,名校大厂高手同台 PK,“马栏山杯”国际音视频算法大赛来袭!...
在刚结束的计算机视觉顶级学术会议CVPR 2021上,涌现了多种优秀的计算机视觉AI算法解决方案. 其中最佳论文奖为<GIRAFFE:Representing Scenes as Composi ...
最新文章
- 有感于任正非老爷子的发言
- 《系统集成项目管理工程师》必背100个知识点-78配置项的版本控制
- *.zip、*.tar、*.tar.gz、*.tar.bz2、*.tar.xz、*.jar、*.7z
- 现在中国是以24枚金牌位列奖牌榜3位,美国英国分列1、2位
- php ajax loading图片居中显示,php-通过ajax框架加载漂亮照片
- 【BZOJ3514】Codechef MARCH14 GERALD07加强版,LCT+主席树
- AFNetWork 学习资源....
- python中get属性_python3中__get__,__getattr__,__getattribute__的区别
- Excel实现Base16-Base64编码转换(SAP SCM)
- 如何把流程图转换为软件设计(初稿)
- Windows 10 (Win10) 将绿色免安装软件,添加到动态磁贴
- 【转】linux服务器的Gzip文件压缩方法
- 中国互联网的沧海桑田
- pip永久修改下载源(豆瓣源)
- sleep(0) 的作用
- WebServices | 期末复习 · WebService基本概念、XML
- 功能多变的可视化对象- Distribution
- SQLServer中用户 'sa' 登录失败解决办法
- 如何在xmd上运行java文件,Java学习笔记(一)
- ARM-A架构入门基础(三)MMU