用c对图像做直方图均匀化,为什么只有1/3的图像被作用了呀
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef unsigned char BYTE; // 定义BYTE为一个字节的类型
typedef unsigned short WORD; // 定义WORD为两个字节的类型
typedef unsigned int DWORD; // 定义DWORD为四个字节的类型
//#pragma pack(2)
int main()
{
BYTE* in ;
BYTE* out;
BYTE* a;
BYTE* b;
BYTE* ptr;
int shu1[256], shu2[256], shu3[256], p, W, H;
memset(shu1, 0, sizeof(int) * 256);
memset(shu2, 0, sizeof(int) * 256);
memset(shu3, 0, sizeof(int) * 256);
fopen_s(&in, "E:\\cxc.bmp", "rb+");
fseek(in, 18, SEEK_SET);
fread(&W, 4, 1, in);
fseek(in, 22, SEEK_SET);
fread(&H, 4, 1, in);
fseek(in, 0, SEEK_SET);
ptr = (unsigned char*)malloc((((W * 24 / 8 + 3) / 4 * 4) * H + 54)*sizeof(BYTE));
fread(ptr, 1, ((W * 24 / 8 + 3) / 4 * 4) * H + 54, in);
b = ptr + ((W * 24 / 8 + 3) / 4 * 4) * H + 54;
for (a=ptr+54;a<b;)
{
shu1[*(a++)]++;
}
for (p = 1, shu2[0] = shu1[0]; p < 256; p++)
{
shu2[p] = shu2[p - 1] + shu1[p];
}
for (p = 0; p < 256; p++)
{
shu3[p] = 255 * shu2[p] / (W * H);
}
for (a=ptr+54;a<b;)
{
*(a++) = shu3[*a];
}
fopen_s(&out, "E:\\gaoqinbancxc.bmp", "wb");
fwrite(ptr, 1, ((W * 24 / 8 + 3) / 4 * 4) * H + 54, out);
fclose(in);
fclose(out);
return 0;
}