找回密码
 立即注册

C语言关于DCT变换压缩编码的程序

[复制链接]
发表于 6 天前 | 显示全部楼层 |阅读模式
资源类型:行业应用 » 企业管理 . 资源来源:网友投递
来历版块:C/C++
压缩包内文件格式:可执行文件
附件来历:互联网
运行方式:Windows方式
是不是经本人验证:是
附件性质:免费
详细说明:#includestdio.h
#includemath.h
#definePI3.1415926
#defineN8
voidyuanshi(inta)//输出初始数据
{inti,j;
for(i=0;i
for(j=0;j
{
printf(%d,a);
if(j==7)
printf(\n);
}
}
voidDCT(intf,floatm)//DCT转换子程序
{
intx,y,i,j,l;
floatcoff,doff,D={0};
for(y=0;y//计算第一行的coff
coff=(sqrt(2.0)/sqrt(N))
(sqrt(1.0)/sqrt(2.0));
for(x=1;x//计算后边N-1行的coff
{
for(y=0;y
coff=(sqrt(2.0)/sqrt(N))
cos((2
(y+1)-1)
x
PI/(2
N));
}
printf(COFF:\n);//输出矩阵coff
for(i=0;i
for(j=0;j
{printf(%f,coff);
if(j==7)
printf(\n);}
for(x=0;x//求coff的转置矩阵doff
{
for(y=0;y
doff=coff;
}
for(i=0;i//矩阵doff和f矩阵相乘,成果为矩阵D
for(l=0;l
{D=0;
for(j=0;j
D=D+doff
(1.0
f);
}
printf(\n);
for(i=0;i//矩阵D和矩阵coff相乘,成果为矩阵m,即通过DCT转换//得到的矩阵
for(l=0;l
{m=0;
for(j=0;j
m=m+D
coff;
}
printf(输出DCT矩阵\n);
for(i=0;i//输出通过DCT转换的成果矩阵m
{for(l=0;l
printf(%f,m);
printf(\n);
}
}
voidsch(intte,floatm,intn)//量化子程序
{
intx,y;
inttr;
for(x=0;x
for(y=0;y
{
tr=(int)(m/te);
n=tr;
printf(%d,tr);
if(y==7)
printf(\n);
}
}
intbianma(intn,intc)//一维行程编码
{
intk,a,i,j,t=0,e=1,d=0,l;
for(i=0;i把二维的编码数组转换成一维数组
for(j=0;j
k=n;
for(i=0;i计算编码后的数据,将其存在数组a中
{l=i+1;
if(k==k)e++;
else{
a=e;
a=k;
e=1;
}
}
printf(编码输出:\n);
for(i=0;i输出编码后的数据
{printf(%d,a);
c=a;//把得到的编码后的数组a的值复制到数组c中
}
printf(\n);
returnd;//返回数组c的长度
}
voidmain()
{/
8
8图画块数据如下
/
floatm,b;
intY=128,i=0,j=0,s,number,n,c,data;
inta={{130,130,130,129,134,133,129,130},{130,130,130,129,134,133,130,130},{130,130,130,129,132,132,130,130},{129,130,130,129,130,130,129,129},{127,128,127,129,131,129,131,130},{127,128,127,128,127,128,132,132},{125,126,129,129,127,129,133,132},{127,125,128,128,126,130,131,131}};
intFy={{16,11,10,16,24,40,51,61},{12,12,14,19,26,58,60,55},{14,13,16,24,40,57,69,56},{14,17,22,29,51,87,80,62},{18,22,37,56,68,109,103,77},{24,35,55,64,81,104,103,77},{49,64,78,87,103,121,120,101},{72,92,95,98,112,100,103,99}};
printf(8
8图画块数据:\n);//输出需求管理的图象数据块的数据
yuanshi(a);//调用初始图画模块程序
printf(转换系数矩阵:\n);
DCT(a,m);//调用DCT转换函数
printf(输出量化后的矩阵:\n);
sch(Fy,m,n);//调用量化函数
number=bianma(n,c);//调用编码函数
printf(初始数据量:\n);
printf(%d\n,s=8
64);//输出初始数据量
printf(编码后的数据总量:\n);
data=number/2
3+number/2
8;
printf(%d\n,data);//输出编码后的数据总量
printf(压缩率:\n);
printf(%f%%\n,data
1.0/s
100);//输出压缩率
}
113223421412.doc

(Origin section: C/C  
The file format in the compressed package: executable file
Attachment source: Internet
Operation mode: Windows mode
Is it verified by me: yes
Attachment nature: free
Detailed description: #includestdio.h
#includemath.h
#definePI3.1415926
#defineN8
voidyuanshi(inta)//Output initial data
{inti,j;
for(i=0;i
for(j=0;j
{
printf(
a);
if(j==7)
printf(\n);
}
}
voidDCT(intf,floatm)//DCT conversion subroutine
{
intx,y,i,j,l;
floatcoff,doff,D={0};
for(y=0;y//Calculate the coff of the first line
coff=(sqrt(2.0)/sqrt(N))
(sqrt(1.0)/sqrt(2.0));
for(x=1;x//Calculate the coff of the next N-1 lines
{
for(y=0;y
coff=(sqrt(2.0)/sqrt(N))
cos((2
(y 1)-1)
x
PI/(2
N));
}
printf(COFF:\n);//Output matrix coff
for(i=0;i
for(j=0;j
{printf(coff);
if(j==7)
printf(\n);}
for(x=0;x//Find the transposed matrix doff of coff
{
for(y=0;y
doff=coff;
}
for(i=0;i//Matrix doff and f matrix are multiplied, the result is matrix D
for(l=0;l
{D=0;
for(j=0;j
D=D doff
(1.0
f);
}
printf(\n);
for(i=0;i//Matrix D and matrix coff are multiplied, the result is matrix m, that is, the matrix obtained by DCT transformation//
for(l=0;l
{m=0;
for(j=0;j
m=m D
coff;
}
printf(output DCT matrix\n);
for(i=0;i//Output the result matrix m converted by DCT
{for(l=0;l
printf(m);
printf(\n);
}
}
voidsch(intte,floatm,intn)//quantization subroutine
{
intx,y;
inttr;
for(x=0;x
for(y=0;y
{
tr=(int)(m/te);
n=tr;
printf(
tr);
if(y==7)
printf(\n);
}
}
intbianma(intn,intc)//One-dimensional run-length encoding
{
intk,a,i,j,t=0,e=1,d=0,l;
for(i=0;i converts a two-dimensional encoded array into a one-dimensional array
for(j=0;j
k=n;
for(i=0;i calculates the encoded data and stores it in the array a
{l=i 1;
if(k==k)e  ;
else{
a=e;
a=k;
e=1;
}
}
printf(encoded output:\n);
for(i=0;i outputs the encoded data
{printf(
a);
c=a;//Copy the value of the encoded array a to the array c
}
printf(\n);
returned;//return the length of the array c
}
voidmain()
{/
8
The 8-picture block data is as follows
/
floatm,b;
intY=128,i=0,j=0,s,number,n,c,data;
inta={{130,130,130,129,134,133,129,130},{130,130,130,129,134,133,130,130},{130,130,130,129,132,132,130,130},{129,130,130,129,130,130,129,129},{127,128,127,129,131,129,131,130},{127,128,127,128,127,128,132,132},{125,126,129,129,127,129,133,132},{127,125,128,128,126,130,131,131}};
intFy={{16,11,10,16,24,40,51,61},{12,12,14,19,26,58,60,55},{14,13,16,24,40, 57,69,56},{14,17,22,29,51,87,80,62},{18,22,37,56,68,109,103,77},{24,35,55,64,81,104,103, 77},{49,64,78,87,103,121,120,101},{72,92,95,98,112,100,103,99}};
printf(8
8 image block data:\n);//Output the data of the image data block of demand management
yuanshi(a);//Call the initial drawing module program
printf(Conversion coefficient matrix:\n);
DCT(a,m);//Call the DCT conversion function
printf(output quantized matrix:\n);
sch(Fy,m,n);//Call the quantization function
number=bianma(n,c);//Call the encoding function
printf(initial amount of data:\n);
printf(
n,s=8
64);//Output the initial amount of data
printf(Total amount of encoded data:\n);
data=number/2
3 number/2
8;
printf(
n,data);//Output the total amount of encoded data
printf(compression ratio:\n);
printf(%\n,data
1.0/s
100);//Output compression ratio
}
113223421412.doc)

[下载]15273860270.rar






上一篇:呼叫中心源程序VC_
下一篇:Visual C++ 2005系列教程

使用道具 举报

Archiver|手机版|小黑屋|English Version|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved

关于本站 - 版权申明 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

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