要求:
对down.rgb和down.yuv分析三个通道的概率分布,并计算各自的熵。(编程实现)两个文件的分辨率均为256*256,yuv为4:2:0采样空间,存储格式为:rgb文件按每个像素BGR分量依次存放;YUV格式按照全部像素的Y数据块、U数据块和V数据块依次存放。
*down.rgb
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
#define A 65536
int main()
{
//打开,创建文件
FILE* image, * red, * green,*blue;
fopen_s(&image, "C:\\Users\\admin\\Desktop\\数据压缩作业\\down.rgb", "rb");
fopen_s(&red, "C:\\Users\\admin\\Desktop\\数据压缩作业\\Red.txt", "w");
fopen_s(&green, "C:\\Users\\admin\\Desktop\\数据压缩作业\\Green.txt", "w");
fopen_s(&blue, "C:\\Users\\admin\\Desktop\\数据压缩作业\\Blue.txt", "w");
//定义R、G、B分量
unsigned char R[A] = {
0 },G[A] = {
0 }, B[A] = {
0 };
//定义频率分量
double R_F[256] = {
0 },G_F[256] = {
0 },B_F[256] = {
0 };
//定义熵
double R_S = 0,G_S = 0, B_S = 0;
//分别读取R、G、B三个分量到数组中
unsigned char sum[256*256*3];
fread(sum, 1, 256*256*3, image);
for (int i = 0, j = 0; i < 256*256*3; i = i + 3, j++)
{
B[j] = *(sum + i);
G[j] = *(sum + i + 1);
R[j] = *(sum + i + 2);
}
//计数三通道各颜色值次数
for (int i =