down.rgb和down.yuv各自的熵

RGB熵的计算

#include"stdio.h"
#include"math.h"
#include"iostream"
#include"windows.h"
using namespace std;
#define MAX 256
void main()
{
float count[MAX]={0};
float h[3]={0};
float iq;
int rgb;
int size=256256,total=256256*3;
unsigned char *RGB_buffer_in;
unsigned char *RGB;
unsigned char *buffer;
RGB_buffer_in=new unsigned char[total];
RGB=new unsigned char[total];
FILE *fp;
fp=fopen(“E:/大三下课程/数据压缩/down.rgb”,“r”);
if(fp==NULL)
{printf(“File not open!/n”);}
fread(RGB_buffer_in,sizeof(unsigned char),total,fp);
for(int i=0;i<3;i++)
{
buffer=RGB_buffer_in;
for(int j=0;j<size;j++)
{
RGB=buffer;
RGB++;
buffer+=3;
}
RGB_buffer_in++;
}
for(rgb=0;rgb<3;rgb++)
{
for(int i=0;i<size;i++)
{
int m=RGB[i];
count[m]++;
}
for(int i=0;i<MAX;i++)
{
count[i]=count[i]/size;
if(count[i]!=0)
{
iq=log(count[i])/log(2.0);
h[rgb]=h[rgb]-count[i]*iq;
}
}
}
fclose(fp);
printf(“B的熵为:%f\n”,h[0]);
printf(“G的熵为:%f\n”,h[1]);
printf(“R的熵为:%f\n”,h[2]);
system(“pause”);
return;
}
结果: R的熵为:7.22955
G的熵为:7.17846
B的熵为:6.85686

YUV熵的计算

#include<stdio.h>
#include
#include<stdio.h>
#include<math.h>
#define MAX 256
void main()

{
float count[MAX]={0};
float h[3]={0};
float iq;
int yuv;
int size=256*256;
unsigned char *YUV_buffer_in;
YUV_buffer_in=new unsigned char[size];
FILE *fp;
fp=fopen(“E:/大三下课程/数据压缩/down.yuv”,“r”);
if(fp==NULL)
{printf(“File not open!/n”);}
for(yuv=0;yuv<3;yuv++)
{
fread(YUV_buffer_in,sizeof(unsigned char),size,fp);
for(int i=0;i<size;i++)
{
int m=YUV_buffer_in[i];
count[m]++;
}
for(int i=0;i<MAX;i++)
{
count[i]=count[i]/size;
if(count[i]!=0)
{
iq=log(count[i])/log(2.0);
h[yuv]=h[yuv]-count[i]*iq;
}
}
}
fclose(fp);
printf(“Y的熵为:%f\n”,h[0]);
printf(“U的熵为:%f\n”,h[1]);
printf(“V的熵为:%f\n”,h[2]);
return ;
}
结果:Y的熵为:6.33182
U的熵为:5.1264
V的熵为:4.11314

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值