用C++分析RGB、YUV格式图片并计算RGB、YUV各分量的熵
前言
上一学期使用C/C++ 学习了一些对YUV文件的分析方法,本次任务在复习了上学期代码的基础上开展。
一、学习任务
对发的down.rgb和down.yuv分析三个通道的概率分布,并计算各自的熵(编程实现)。两个文件的分辨率均为256*256,yuv为4:2:0采样空间,存储格式为:RGB文件按每个像素BGR分量依次存放;YUV格式按照全部像素的Y数据块、U数据块和V数据块依次存放。
二、RGB文件
1、任务思路
- 打开文件,写入数据。
- 根据BGR次序将三通道数据进行分离。
- 统计各通道不同灰度级出现的频数。
- 由得到的频数计算概率。
- 由得到的概率计算熵值。
2、代码实现
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<math.h>
using namespace std;
#define SIZE 256 * 256 //分辨率
int main()
{
//变量定义
unsigned char data[SIZE * 3]; //rgb文件数据
unsigned char data_R[SIZE], data_G[SIZE], data_B[SIZE]; //分离RGB数据
double pro_R[256] = { 0 }, pro_G[256] = { 0 }, pro_B[256] = { 0 }; //RGB概率分量
double ent_R = 0, ent_G = 0, ent_B = 0; //RGB的熵
//打开文件,写入数据。
FILE* file = fopen("down.rgb", "rb");
fread(data, 1, SIZE * 3, file);
//根据BGR次序将三通道数据进行分离。
for (int i = 0, j = 0; i < SIZE * 3; i = i + 3, j++)
{
data_B[j] = *(data + i);
data_G[j] = *(data + i + 1);
data_R[j] = *(data + i + 2);
}
//统计各通道不同灰度级出现的频数。
for (int i = 0; i < SIZE; i++)
{
pro_R[data_R[i]]++;
pro_G[data_G[i]]++;
pro_B[data_B[i]]++;
}
//由得到的频数计算概率。
for (int i = 0; i < 256; i++)
{
pro_R[i] = pro_R[i] / (SIZE);
pro_B[i] = pro_B[i] / (SIZE);
pro_G[i] = pro_G[i] / (SIZE);
}
//由得到的概率计算熵值。
for (int i = 0; i < 256; i++)
{
if (pro_R[i] != 0)
{
ent_R = ent_R - pro_R[i] * log(pro_R[i]) / log(2);
}
if (pro_G[i] != 0)
{
ent_G = ent_G - pro_G[i] * log(pro_G[i]) / log(2);
}
if (pro_B[i] != 0)
{
ent_B = ent_B - pro_B[i] * log(pro_B[i]) / log(2);
}
}
cout << "R的熵为: " << ent_R << endl;
cout << "G的熵为: " << ent_G << endl;
cout << "B的熵为: " << ent_B << endl;
return 0;
}
运行结果如下。
3、问题记录
- 用
fopen
函数会报错,上网查了一下得到的解决方法是在代码段最前端加入一句话#define _CRT_SECURE_NO_DEPRECATE
,这样程序就正常运行了。 - 起初程序正常运行但是熵值输出出现以下错误:
百度查了下说是出现了无效数字,但是还是不知道怎么改,问了问同学之后把变量定义部分的double pro_R[256] = { 0 }, pro_G[256] = { 0 }, pro_B[256] = { 0 };
这三个变量进行了初始化就好了,没想明白是为什么,不过未来定义变量时尽量进行初始化应该会好些。
4、三通道概率分布
step1
数据作图我选择了用matlab来作,方法比较简单粗暴,在代码计算概率的后面加上一段代码对三个通道各个灰度出现的频次进行cout
输出即:
for (int i = 0; i < 256; i++)
{
//cout << pro_R[i] << " ";
//cout << pro_B[i] << " ";
cout << pro_G[i] << " ";
}
输出一个通道时把另外两个注释掉,这样分别得出了三个通道各个灰度出现的频次。(下图为G通道频次)
真的好简单粗暴。。
step2
直接将得到的结果复制粘贴到matlab的变量中,进行绘图。
matlab代码如下。
r = [0.0059967 0.0158539 0.011734 0.0116425 0.0127411 0.0158234 0.0169067 0.0184784 0.0204315 0.0258331 0.0282898 0.0540924 0.0123138 0.00872803 0.00831604 0.00767517 0.0072937 0.00733948 0.00674438 0.00704956 0.00679016 0.00688171 0.00764465 0.00733948 0.00688171 0.00753784 0.00724792 0.00679016 0.00741577 0.00717163 0.00653076 0.00726318 0.00735474 0.00718689 0.00660706 0.00672913 0.00747681 0.00735474 0.00816345 0.00738525 0.00775146 0.00802612 0.00787354 0.00759888 0.00761414 0.00695801 0.00642395 0.00636292 0.00646973 0.00646973 0.00645447 0.00631714 0.0062561 0.00579834 0.00546265 0.00605774 0.00631714 0.00582886 0.00617981 0.00657654 0.00737 0.00717163 0.00640869 0.00643921 0.00746155 0.00743103 0.00561523 0.00527954 0.00559998 0.00521851 0.00575256 0.00454712 0.00427246 0.00396729 0.00349426 0.00274658 0.00309753 0.00314331 0.00280762 0.00285339 0.00247192 0.00245667 0.00204468 0.00234985 0.00204468 0.00234985 0.00187683 0.00212097 0.00196838 0.00184631 0.00196838 0.0020752 0.00170898 0.0017395 0.00167847 0.00201416 0.00137329 0.00192261 0.00184631 0.00160217 0.00163269 0.00163269 0.0017395 0.00125122 0.00167847 0.00132751 0.00108337 0.00151062 0.00149536 0.00144958 0.00123596 0.00144958 0.0014801 0.00160217 0.00140381 0.00140381 0.0014801 0.00128174 0.001297 0.00138855 0.00151062 0.00152588 0.00177002 0.00186157 0.00233459 0.00256348 0.00289917 0.00282288 0.00312805 0.00299072 0.00370789 0.00360107 0.00386047 0.00424194 0.00476074 0.00520325 0.00570679 0.00552368 0.00592041 0.00662231 0.00691223 0.00706482 0.00682068 0.00575256 0.00502014 0.00430298 0.00344849 0.0032196 0.00331116 0.00393677 0.00343323 0.00346375 0.00341797 0.00328064 0.0027771 0.00289917 0.00300598 0.00306702 0.00309753 0.0032196 0.0030365 0.00294495 0.00276184 0.00259399 0.00234985 0.00234985 0.00209045 0.00221252 0.0020752 0.00213623 0.00201416 0.0020752 0.00190735 0.00195313 0.00202942 0.0019989 0.00172424 0.00177002 0.00183105 0.00167847 0.00163269 0.0017395 0.00158691 0.00190735 0.00183105 0.0018158 0.00180054 0.00160217 0.00144958 0.00125122 0.00123596 0.00111389 0.00125122 0.00120544 0.00112915 0.00108337 0.00088501 0.00119019 0.00105286 0.00108337 0.00106812 0.00158691 0.00140381 0.00146484 0.00131226 0.00158691 0.00137329 0.00166321 0.00195313 0.00186157 0.00158691 0.00158691 0.00167847 0.00141907 0.00106812 0.000747681 0.000701904 0.000366211 0.000366211 0.000213623 0.00038147 0.000213623 0.000137329 4.57764e-05 0 0 0 3.05176e-05 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
g = [0 0 0 0 0 0 0 4.57764e-05 1.52588e-05 7.62939e-05 0.000167847 0.000305176 0.000534058 0.000991821 0.00338745 0.0183105 0.0359955 0.0447845 0.0832977 0.0355988 0.0234833 0.0212708 0.0193024 0.0177155 0.0168152 0.0151978 0.0147247 0.0127716 0.0129547 0.0122375 0.0117188 0.0110626 0.0111847 0.0106659 0.00927734 0.00860596 0.00836182 0.00753784 0.00683594 0.00617981 0.00559998 0.00511169 0.00483704 0.00462341 0.00421143 0.00398254 0.00428772 0.0040741 0.00361633 0.00387573 0.00379944 0.00338745 0.00384521 0.00367737 0.003479 0.00338745 0.0030365 0.00334167 0.00315857 0.00338745 0.00323486 0.00300598 0.00360107 0.00328064 0.00367737 0.00326538 0.00328064 0.003479 0.00340271 0.00312805 0.00259399 0.00299072 0.00299072 0.00270081 0.00280762 0.00257874 0.00247192 0.00244141 0.00248718 0.00230408 0.00228882 0.00231934 0.00234985 0.00218201 0.00213623 0.00192261 0.00210571 0.00190735 0.00195313 0.00183105 0.00183105 0.00158691 0.00172424 0.00175476 0.00164795 0.00180054 0.0017395 0.001297 0.00152588 0.00143433 0.0015564 0.00138855 0.00169373 0.00158691 0.0014801 0.00175476 0.00164795 0.00218201 0.00332642 0.00289917 0.00268555 0.00346375 0.00294495 0.00202942 0.00186157 0.00204468 0.00250244 0.00262451 0.00260925 0.00244141 0.00309753 0.00263977 0.0027771 0.00204468 0.00222778 0.00196838 0.00157166 0.00187683 0.00230408 0.00213623 0.0019989 0.00144958 0.00161743 0.00131226 0.00132751 0.00141907 0.00120544 0.00128174 0.00137329 0.00108337 0.000869751 0.000991821 0.000915527 0.00106812 0.000854492 0.000930786 0.0010376 0.00119019 0.00109863 0.000717163 0.000900269 0.000915527 0.000671387 0.000762939 0.000640869 0.000595093 0.000717163 0.000854492 0.00088501 0.000732422 0.000534058 0.000717163 0.000869751 0.00062561 0.000854492 0.000686646 0.000778198 0.000732422 0.000823975 0.00102234 0.000793457 0.00126648 0.00137329 0.00140381 0.00177002 0.00152588 0.00149536 0.00163269 0.00161743 0.00195313 0.00164795 0.00219727 0.00236511 0.00265503 0.00335693 0.00376892 0.00396729 0.00354004 0.00357056 0.00358582 0.00418091 0.00396729 0.00410461 0.00482178 0.00553894 0.00675964 0.00686646 0.00924683 0.0106659 0.0119019 0.0100555 0.00852966 0.0112 0.0138397 0.00993347 0.00900269 0.00595093 0.00434875 0.00309753 0.00286865 0.00302124 0.00212097 0.00195313 0.00195313 0.0018158 0.00169373 0.00158691 0.00138855 0.0014801 0.0015564 0.00198364 0.0020752 0.0020752 0.00202942 0.00158691 0.00169373 0.00204468 0.00198364 0.00180054 0.00196838 0.00180054 0.00135803 0.000946045 0.000518799 0.000442505 0.000213623 0.000274658 0.000305176 0.000213623 9.15527e-05 0 1.52588e-05 1.52588e-05 0 0 0 0 0 0 0 0 0 0 0 0 0];
b = [0 0 0 0 0 0 0 3.05176e-05 0 6.10352e-05 0.000152588 0.000595093 0.0012207 0.00256348 0.00956726 0.0549164 0.0200195 0.0157776 0.0147552 0.0126953 0.0108795 0.0109863 0.00997925 0.00924683 0.00985718 0.00965881 0.00900269 0.00927734 0.00967407 0.00949097 0.00964355 0.0100708 0.0102692 0.0105896 0.0115814 0.011795 0.0118103 0.0118866 0.0119781 0.0119019 0.0113373 0.0107269 0.0104218 0.0101624 0.00993347 0.0101318 0.00917053 0.0098114 0.00915527 0.00924683 0.00961304 0.00942993 0.00968933 0.00935364 0.00830078 0.00967407 0.00798035 0.00805664 0.00822449 0.00752258 0.00802612 0.00717163 0.00692749 0.0071106 0.00656128 0.00636292 0.00634766 0.00572205 0.00518799 0.00479126 0.00523376 0.00483704 0.00396729 0.00462341 0.00549316 0.00592041 0.00631714 0.00595093 0.00509644 0.00465393 0.00468445 0.00482178 0.0045166 0.00430298 0.00444031 0.00469971 0.00387573 0.00376892 0.00344849 0.00312805 0.00312805 0.00367737 0.00349426 0.00279236 0.00247192 0.00238037 0.00204468 0.00198364 0.00189209 0.00192261 0.00154114 0.00163269 0.00198364 0.00175476 0.00172424 0.0015564 0.00166321 0.001297 0.00138855 0.00135803 0.0015564 0.00109863 0.0014801 0.00123596 0.00108337 0.00115967 0.00106812 0.000976563 0.00108337 0.000976563 0.00117493 0.00100708 0.00088501 0.00105286 0.000869751 0.000839233 0.000976563 0.000793457 0.000701904 0.000900269 0.000823975 0.00115967 0.000930786 0.000839233 0.00128174 0.00106812 0.00108337 0.00134277 0.000991821 0.00114441 0.0014801 0.00123596 0.00135803 0.00125122 0.00126648 0.0014801 0.00172424 0.00164795 0.00195313 0.00209045 0.00209045 0.00190735 0.00210571 0.00201416 0.00233459 0.00291443 0.0032196 0.00361633 0.00395203 0.00402832 0.00442505 0.0043335 0.0045166 0.00544739 0.00534058 0.00614929 0.00639343 0.00627136 0.00683594 0.00756836 0.00765991 0.00839233 0.00779724 0.00770569 0.00674438 0.00520325 0.0057373 0.00596619 0.00506592 0.00418091 0.00364685 0.00292969 0.00242615 0.00256348 0.0025177 0.00228882 0.00244141 0.00190735 0.00167847 0.0018158 0.00212097 0.00205994 0.0022583 0.0015564 0.00183105 0.00184631 0.00164795 0.00120544 0.00138855 0.00105286 0.00128174 0.00088501 0.000854492 0.00105286 0.000976563 0.00105286 0.00117493 0.00102234 0.00112915 0.00126648 0.00111389 0.00112915 0.00131226 0.000991821 0.00140381 0.00141907 0.00186157 0.00172424 0.00160217 0.00163269 0.00160217 0.00170898 0.00106812 0.000701904 0.000671387 0.000534058 0.000274658 0.000274658 0.000335693 0.000152588 1.52588e-05 1.52588e-05 1.52588e-05 1.52588e-05 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
plot(r,'r');hold on;
plot(g,'g');hold on;
plot(b,'b');hold on;
xlabel('灰度值');
ylabel('概率');
legend('r','g','b');
输出结果即概率分布图如下。
三、YUV文件
1、任务思路
- 思路与处理rgb文件相同,唯一不同点在于YUV文件数据存储格式为YYY…UUU…VVV…,在进行YUV通道分离时要注意更改。
- YUV文件为4:2:0采样空间,因此在许多地方YUV分量要分开处理。
2、代码实现
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<math.h>
using namespace std;
#define SIZE 256 * 256 //分辨率
int main()
{
//变量定义
unsigned char data[98304]; //yuv文件数据,4:2:0采样
//为了不涉及类型转换错误,SIZE*1.5=98304
unsigned char data_Y[SIZE], data_U[SIZE / 4], data_V[SIZE / 4]; //分离YUV数据
double pro_Y[256] = { 0 }, pro_U[256] = { 0 }, pro_V[256] = { 0 }; //YUV概率分量
double ent_Y = 0, ent_U = 0, ent_V = 0; //YUV的熵
//文件打开、写入
FILE* file = fopen("down.yuv", "rb");
fread(data, 1, 98304, file);//SIZE*1.5=98304
//分离YUV三通道
for (int i = 0, j = 0; i < SIZE; i++, j++)
{
data_Y[j] = *(data + i);
}
for (int i = SIZE, j = 0; i < 81920; i++, j++)//SIZE*1.25=81920
{
data_U[j] = *(data + i);
}
for (int i = 81920, j = 0; i < 98304; i = i + 1, j++)//SIZE*1.5=98304
{
data_V[j] = *(data + i);
}
//分别统计YUV三通道不同灰度级出现频数
for (int i = 0; i < SIZE; i++)
{
pro_Y[data_Y[i]]++;
}
for (int i = 0; i < SIZE / 4; i++)
{
pro_U[data_U[i]]++;
pro_V[data_V[i]]++;
}
//分别计算YUV三通道不同灰度级出现的概率
for (int i = 0; i < 256; i++)
{
pro_Y[i] = pro_Y[i] / (SIZE);
pro_U[i] = pro_U[i] / (SIZE / 4);
pro_V[i] = pro_V[i] / (SIZE / 4);
}
//计算并输出熵
for (int i = 0; i < 256; i++)
{
if (pro_Y[i] != 0)
{
ent_Y = ent_Y - pro_Y[i] * log(pro_Y[i]) / log(2);
}
if (pro_U[i] != 0)
{
ent_U = ent_U - pro_U[i] * log(pro_U[i]) / log(2);
}
if (pro_V[i] != 0)
{
ent_V = ent_V - pro_V[i] * log(pro_V[i]) / log(2);
}
}
cout << "Y的熵为: " << ent_Y << endl;
cout << "U的熵为: " << ent_U << endl;
cout << "V的熵为: " << ent_V << endl;
return 0;
}
运行结果如下。
3、问题记录
PS.本以为复制粘贴rgb的代码稍作修改就可实现,但是毕竟rgb文件和yuv文件储存上有不少区别还是修改了许多地方。
- 首先是数据类型问题,在频繁发现有波浪线警告我数据类型问题后,选择了简单粗暴的处理方法,例如
unsigned char data[98304]; //SIZE*1.5=98304
这里直接将计算机过填入数组定义里,避免了[]
中的运算,后续类似问题也是如此处理。 - 由于YUV按顺序存储,因此在分离通道写入数据时,原本用在rgb的方法不可行,便分别采用了三个循环写入数据。
- 统计频数时,由于分量的数据量不同,Y和UV分成了两部分统计。
4、三通道概率分布
数据作图方法同上,这里展示代码和结果。
- C++中代码:
for (int i = 0; i < 256; i++)
{
//需要输出哪一段把哪一段注释删除
//cout << pro_Y[i] << " ";
//cout << pro_U[i] << " ";
//cout << pro_V[i] << " ";
}
cout << endl;
- matlab中代码:
y = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.174591 0.00125122 0.026825 0.00588989 0.0105286 0.00595093 0.000396729 0.0269318 0.004776 0.0101624 0.0237885 0.00680542 0.0119171 0.00415039 0.00947571 0.00437927 0.00639343 0.0161285 0.0121918 0.0122223 0.0107117 0.00967407 0.00537109 0.00828552 0.00694275 0.00921631 0.00798035 0.0111847 0.00724792 0.0137787 0.00646973 0.0114594 0.0088501 0.00588989 0.0065155 0.00588989 0.0070343 0.0106659 0.00640869 0.0120697 0.00637817 0.0059967 0.00274658 0.00408936 0.00541687 0.00610352 0.00724792 0.00798035 0.00521851 0.0042572 0.00131226 0.00253296 0.00259399 0.00434875 0.0120239 0.00701904 0.00534058 0.00444031 0.0025177 0.0012207 0.00175476 0.00259399 0.00994873 0.00994873 0.00410461 0.00276184 0.00183105 0.000793457 0.00302124 0.00190735 0.00386047 0.0070343 0.00405884 0.00326538 0.00141907 0.000915527 0.00143433 0.00151062 0.00146484 0.00234985 0.00387573 0.00216675 0.00112915 0.00105286 0.00050354 0.000839233 0.00126648 0.00170898 0.00398254 0.0025177 0.000900269 0.00141907 0.000167847 0.000442505 0.000762939 0.000717163 0.00341797 0.0019989 0.000320435 0.000946045 0.000198364 0.000427246 0.000350952 0.000488281 0.00419617 0.000839233 0.000350952 0.000823975 0.000198364 0.000747681 0.000106812 0.000686646 0.00419617 0.000961304 9.15527e-05 0.000732422 0.00134277 0.00117493 0.000198364 0.00100708 0.00421143 0.0012207 9.15527e-05 0.000701904 0.0038147 0.00247192 0.000839233 0.00135803 0.00527954 0.000946045 0.00260925 0.00115967 0.00462341 0.00495911 0.00273132 0.00108337 0.00959778 0.00117493 0.00959778 0.000732422 0.013031 0.00270081 0.0080719 0.00361633 0.00914001 0.00402832 0.0186157 0.00489807 0.0025177 0.0109863 0.00523376 0.00404358 0.00712585 0.00448608 0.00088501 0.000762939 0.000106812 0.00679016 0.000167847 0.00570679 0.00819397 0.000671387 0.00140381 0.000244141 4.57764e-05 0.00123596 0.000106812 0.0103302 0.00218201 0.000869751 0.000762939 0.000167847 0 0.000549316 0.000427246 0.00820923 0.000152588 0.00164795 0.000137329 1.52588e-05 1.52588e-05 3.05176e-05 0.00164795 0.0052948 4.57764e-05 0.0014801 0 1.52588e-05 3.05176e-05 0 0.0093689 0.00126648 7.62939e-05 0.000213623 0 4.57764e-05 0.000335693 0.000106812 0.00872803 1.52588e-05 0.000274658 0.000289917 0 0 0 0 0.000793457 0 3.05176e-05 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
u = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6.10352e-05 6.10352e-05 6.10352e-05 0.000183105 0.000671387 0.000793457 0.000915527 0.00195313 0.00292969 0.00286865 0.00482178 0.00518799 0.00640869 0.00756836 0.00769043 0.00964355 0.00952148 0.0111084 0.0120239 0.0137329 0.0175781 0.0183716 0.0235596 0.0237427 0.0294189 0.0345459 0.0385742 0.043335 0.046936 0.0556641 0.116699 0.0162964 0.00854492 0.00921631 0.0230713 0.0153809 0.017395 0.0240479 0.039856 0.026123 0.0250244 0.0231934 0.0457764 0.0230713 0.0131836 0.010376 0.0147705 0.0247192 0.0165405 0.0283813 0.0296631 0.0113525 0.00305176 0.00421143 6.10352e-05 0 6.10352e-05 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
v = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0010376 0.00311279 0.00286865 0.00384521 0.022644 0.00860596 0.0100098 0.0129395 0.0202637 0.0160522 0.0248413 0.0455933 0.0513916 0.0485229 0.0577393 0.0662231 0.0922241 0.149902 0.170654 0.0527954 0.034729 0.0231934 0.0227051 0.012207 0.0129395 0.0098877 0.00714111 0.00323486 0.00360107 0.00323486 0.00250244 0.00201416 0.000976563 0.00012207 0.000244141 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
plot(y,'r');hold on;
plot(u,'g');hold on;
plot(v,'b');hold on;
xlabel('灰度值');
ylabel('概率');
legend('y','u','v');
- 概率分布图:
四、总结
- 由熵值可以算出rgb文件熵值比yuv文件熵值小。
- 由概率分布图可以看出rgb文件熵值更大一些(均匀分布的熵最大)。
两种方法得出的结论一致,但是这个比较结果能代表什么暂时还不知道,留个白欢迎牛人评论区帮忙解答。(知道了就回来更新放这里:D