2020.3.9读入一个24bitRGB文件(以down.rgb为例,其分辨率为256*256),输出该数据文件中R、G、B三个分量(各8bit表示)的概率分布示意图(类似下图)和熵。
#include "stdafx.h"
#include <stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
using namespace std;
int main()
{
FILE* photo;
FILE* Bsat;
FILE* Gsat;
FILE* Rsat;
const int width = 256;
const int height = 256;
fopen_s(&photo, "down.rgb", "rb");//打开要读出的RGB文件(以“rb”方式打开)
fopen_s(&Bsat, "B_sat.txt", "w");//打开3个要输出的数据统计文件(以“w”方式打开,可命名为R_sat.txt等)
fopen_s(&Gsat, "G_sat.txt", "w");
fopen_s(&Rsat, "R_sat.txt", "w");
unsigned char* buffer = NULL;
buffer= (unsigned char*)malloc(sizeof(unsigned char) * 3 * width * height);
fread(buffer,sizeof(unsigned char), 3 * width * height, photo);
unsigned char B[width * height] ={
0 };//开辟3个width*height的unsigned char型数组