《信息论与编码》实验报告.docx

上传人:jian****018 文档编号:8264512 上传时间:2020-03-28 格式:DOCX 页数:9 大小:67.80KB
返回 下载 相关 举报
《信息论与编码》实验报告.docx_第1页
第1页 / 共9页
《信息论与编码》实验报告.docx_第2页
第2页 / 共9页
《信息论与编码》实验报告.docx_第3页
第3页 / 共9页
点击查看更多>>
资源描述
信息论与编码实验报告QQ417860489一、实验目的1、理解信源编码的基本原理;2、熟练掌握Huffman编码的方法;3、理解无失真信源编码和限失真编码方法在实际图像信源编码应用中的差异。二、实验设备与软件 1、PC计算机系统 2、VC+6.0语言编程环境 3、基于VC+6.0的图像处理实验基本程序框架imageprocessing4、常用图像浏览编辑软件Acdsee和数据压缩软件winrar。5、实验所需要的bmp格式图像(灰度图象若干幅)。三、实验内容与步骤 1、针对“图像1.bmp”、“图像2.bmp”和“图像3.bmp”进行灰度频率统计(即计算图像灰度直方图),在此基础上添加函数代码构造Huffman码表,针对图像数据进行Huffman编码,观察和分析不同图像信源的编码效率和压缩比。(1)各个图像的灰度频率统计如下(2)对图像1进行Huffman编码,得到码表如下像素值概率分布Huffman编码(未差分)像素值概率分布Huffman编码(未差分)像素值概率分布Huffman编码(未差分)00.0118360001101000.000000011001100110010112000.000000011001100001011010.000000011001100100000001010.01003311001012010.000000011001100001011120.000000011001100100000011020.000000011001100110011002020.01598310010130.000000011001100100000101030.000000011001100110011012030.000000011001100001100040.0213091111011040.000000011001100110011102040.000000011001100001100150.000000011001100100000111050.0194301110002050.000000011001100001101060.000000011001100100001001060.000000011001100110011112060.01524101111070.000000011001100100001011070.000000011001100110100002070.000000011001100001101180.022653000011080.000000011001100110100012080.000000011001100001110090.000000011001100100001101090.0133950100112090.0000000110011000011101100.000000011001100100001111100.000000011001100110100102100.012887010001110.000000011001100100010001110.000000011001100110100112110.0000000110011000011110120.0037240110011011120.000000011001100110101002120.0000000110011000011111130.000000011001100100010011130.0140170101112130.0000000110011000100000140.000000011001100100010101140.000000011001100110101012140.0000000110011000100001150.000000011001100100010111150.000000011001100110101102150.017783101101160.022806000101160.000000011001100110101112160.0000000110011000100010170.000000011001100100011001170.0164751001112170.0000000110011000100011180.000000011001100100011011180.000000011001100110110002180.0000000110011000100100190.000000011001100100011101190.000000011001100110110012190.012412001100200.004404011001111200.000000011001100110110102200.0000000110011000100101210.000000011001100100011111210.0164941010002210.0000000110011000100110220.000000011001100100100001220.000000011001100110110112220.0000000110011000100111230.000000011001100100100011230.000000011001100110111002230.020192111001240.0189911101011240.000000011001100110111012240.0000000110011000101000250.000000011001100100100101250.0181411100002250.0000000110011000101001260.000000011001100100100111260.000000011001100110111102260.0000000110011000101010270.000000011001100100101001270.000000011001100110111112270.017126101010280.0211981110111280.000000011001100111000002280.0000000110011000101011290.000000011001100100101011290.000000011001100111000012290.0000000110011000101100300.000000011001100100101101300.0139580101102300.0000000110011000101101310.000000011001100100101111310.000000011001100111000102310.015326011111320.01028311111001320.000000011001100111000112320.0000000110011000101110330.000000011001100100110001330.000000011001100111001002330.0000000110011000101111340.000000011001100100110011340.0125940011102340.0000000110011000110000350.000000011001100100110101350.000000011001100111001012350.012412001101360.0212701111001360.000000011001100111001102360.0000000110011000110001370.000000011001100100110111370.000000011001100111001112370.0000000110011000110010380.000000011001100100111001380.0135550101012380.0000000110011000110011390.000000011001100100111011390.000000011001100111010002390.015895100011400.0126760011111400.000000011001100111010012400.0000000110011000110100410.000000011001100100111101410.000000011001100111010102410.0000000110011000110101420.000000011001100100111111420.0191441101112420.0000000110011000110110430.000000011001100101000001430.000000011001100111010112430.02472700100440.000000011001100101000011440.000000011001100111011002440.0000000110011000110111450.0155961000011450.000000011001100111011012450.0000000110011000111000460.000000011001100101000101460.0155921000002460.0000000110011000111001470.000000011001100101000111470.000000011001100111011102470.00587211111011480.000000011001100101001001480.000000011001100111011112480.0000000110011000111010490.022113000001490.000000011001100111100002490.0000000110011000111011500.000000011001100101001011500.0132850100102500.0000000110011000111100510.000000011001100101001101510.000000011001100111100012510.014531011010520.000000011001100101001111520.000000011001100111100102520.0000000110011000111101530.005234111110101530.000000011001100111100112530.0000000110011000111110540.000000011001100101010001540.0186201100112540.0000000110011000111111550.000000011001100101010011550.000000011001100111101002550.018734110100560.000000011001100101010101560.00000001100110011110101570.0190691101101570.00000001100110011110110580.000000011001100101010111580.016113100110590.000000011001100101011001590.00000001100110011110111600.000000011001100101011011600.00000001100110011111000610.0180311011111610.00000001100110011111001620.000000011001100101011101620.014222011000630.000000011001100101011111630.00000001100110011111010640.000000011001100101100001640.00000001100110011111011650.0118680001111650.00000001100110011111100660.000000011001100101100011660.017660101100670.000000011001100101100101670.00000001100110011111101680.000000011001100101100111680.00000001100110011111110690.024749001011690.00000001100110011111111700.000000011001100101101001700.018018101110710.000000011001100101101011710.0000000110011000000000720.000000011001100101101101720.0000000110011000000001730.00624701100101730.0000000110011000000010740.000000011001100101101111740.016758101001750.000000011001100101110001750.0000000110011000000011760.000000011001100101110011760.0000000110011000000100770.0147620110111770.0000000110011000000101780.000000011001100101110101780.012868010000790.000000011001100101110111790.0000000110011000000110800.000000011001100101111001800.0000000110011000000111810.0157061000101810.0000000110011000001000820.000000011001100101111011820.0084701100100830.000000011001100101111101830.0000000110011000001001840.000000011001100101111111840.0000000110011000001010850.0206801110101850.0000000110011000001011860.000000011001100110000001860.017607101011870.000000011001100110000011870.0000000110011000001100880.000000011001100110000101880.0000000110011000001101890.0159051001001890.0000000110011000001110900.000000011001100110000111900.021755111111910.000000011001100110001001910.0000000110011000001111920.000000011001100110001011920.0000000110011000010000930.0149480111011930.0000000110011000010001940.000000011001100110001101940.013438010100950.000000011001100110001111950.0000000110011000010010960.000000011001100110010001960.0000000110011000010011970.0183431100011970.0000000110011000010100980.000000011001100110010011980.014837011100990.000000011001100110010101990.0000000110011000010101由表中的规律可以看出,没4个像素点中只有一个的概率不为0,说明此图进行过量化,实际用到的像素点只有64个。(3)各幅图像信源的编码效率和压缩比编码效率():平均每个码符号的最大信息量为logm=log2=1比特/码符号,平均每个信源符号的信息量为H(U)比特/信源符号,平均码长为K码符号/信源符号,则=H(U)K*logm=H(U)K。压缩比(L):在进行Huffman编码前,每个像素由8个比特位表示,编码后平均每个灰度值的码长为K,所以L=8/K。编码效率和压缩比如下表: 质量因子图像信源熵比特/符号平均码长码符号/信源符号编码效率压缩比图像15.92855.96020.99471.3422图像24.40974.44360.99241.8003图像36.70866.73360.99631.1881(4)用到的主要代码如下:void CImageProcessingDoc:OnImageHuffmancode() int m_Width, m_Height, m_SaveWidth;int i,j;/循环变量double hist256 = 0; /概率分布m_Width = m_pDibInit-GetWidth();m_Height = m_pDibInit-GetHeight();m_SaveWidth = m_pDibInit-GetSaveWidth();hx = 0.0; /信源熵km = 0.0; /平均码长ys = 0.0; /压缩比/计算概率分布for(j=0;jm_Height;j+)for(i=0;im_pDibBitsj*m_SaveWidth+i=histm_pDibInit-m_pDibBitsj*m_SaveWidth + i+1.0/double(m_Width*m_Height);/输出概率统计histFILE*fphist; FILE*fpcode; fphist=fopen(hist.txt,w); fpcode=fopen(code.txt,w); for(i=0;i256;i+) fprintf(fphist,%fn,histi);/计算Huffman编码Huffm huffm(256); /实例化Huffman类huffm.Huffman(hist); /huffm.HuffmanCode(); /进行Huffman编码codetype co; /定义code结构体cofor(i=0;i256;i+)if(histi=0)continue; hx = hx - histi*log(histi)/log(2);/信源熵 co = huffm.codei; /读取Huffman编码 km = km + histi*(256-co.start); /计算平均码长/输出编码code for(i=0;i256;i+)co = huffm.codei; for(j=co.start;j256;j+)fprintf(fpcode,%d,(int)(co.bitsj - 0);fprintf(fpcode,n);ys = 8/km; /压缩比 xl = hx/(km); /编码效率 test = 1; /显示判据 UpdateAllViews(NULL);2、利用图像处理软件Acdsee将“图像1.bmp”、“图像2.bmp”和“图像3.bmp”转换为质量因子为10、50、90的JPG格式图像(共生成9幅JPG图像),比较图像格式转换前后数据量的差异,比较不同品质因素对图像质量的影响; 不同质量的图像数据量如下表: 原始105090图像1302 KB35 KB53 KB142 KB图像2302 KB32 KB49 KB114 KB图像3302 KB52 KB78 KB175 KB 由表可见,三幅图原始大小相同,随着质量因子的减小,数据量也均在减小,但各幅图减小压缩比并不相同。3、数据压缩软件winrar将“图像1.bmp”、“图像2.bmp”和“图像3.bmp”分别生成压缩包文件,观察和分析压缩前后数据量的差异;压缩前后数据量如下表: 图像1图像2图像3压缩前302 KB302 KB302 KB压缩后151 KB124 KB218 KB4、针对任意一幅图像,比较原始BMP图像数据量、Huffman编码后的数据量(不含码表)、品质因数分别为10、50、90时的JPG文件数据量和rar压缩包的数据量,分析不同编码方案下图像数据量变化的原因。以图像1为例,其原始BMP图像数据量、Huffman编码后的数据量(不含码表)、品质因数分别为10、50、90时的JPG文件数据量和rar压缩包的数据量分别如下表所示:原始BMPHuffman编码JPGrar压缩包105090302 KB224 KB35 KB53 KB142 KB151 KB由表可知,进行编码后,数据量较原始BMP文件均有减小,其中,Huffman编码和rar压缩包的数据量比较大,这是由于其编码过程中只进行了去除冗余,并没有进行量化,属于无失真编码;而JPG格式的文件数据量随着其品质因数不同差异很大,这是由于在编码过程中进行了量化,从而产生了失真,品质因数越大,图片质量越好,失真越小,文件的数据量也越大。5、先对图像进行差分再进行Huffman编码。 信源熵比特/符号平均码长码符号/信源符号编码效率压缩比图像14.05014.07940.99281.9610图像24.19534.20720.99721.9015图像36.22726.25650.99531.2787经过差分,减小了信源的相关性,故信源熵和平均码长均比不差分时减小,此时的概率分布如下图所示。虽然信源符号的数量从原来的256个变为了511个,但是其概率分布集中在0附近,故信源熵相对不差分时仍有减小。计算概率分布的代码如下,其他代码与第一问类似。/计算概率分布for(j=0;jm_Height;j+)temp1 = 0;temp2 = 0;for(i=0;im_pDibBitsj*m_SaveWidth + i;sub = temp2 - temp1;if(sub_%),建议用较高版本的VS中的C+环境改写(直接打开有语法错误)。
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 工作总结


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!