#include<stdio.h>
#include<math.h>
#define N 256
void main()
{
float count[N]={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(“C://data//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<N;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]);
return;
}
————————————————
版权声明:本文为CSDN博主「weixin_52189060」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_52189060/article/details/114518444