图像增强 直方图均衡化处理C语言实现
图像增强 直方图均衡化处理C语言实现
#ifndef BMP_H_3_INCLUDED
#define BMP_H_3_INCLUDED typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef long LONG;
typedef unsigned char BYTE;
typedef struct tagBITMAPFILEHEADER
{//bmfh WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
}BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER
{//bmih DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
}BITMAPINFOHEADER;
typedef struct tagRGBQUAD
{//rgbq BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
}RGBQUAD;
typedef struct tagBITMAPINFO
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
}BITMAPINFO;
#endif//BMP_H_3_INCLUDED
#include stdio.h
#include stdlib.h
#include string.h
#include malloc.h
#include ctype.h
#include process.h
#include"BMP_3.h"
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
BYTE*imgData;
int N;
void readData();
void HistTrans();
int ReadFileHeader(BITMAPFILEHEADER*);
int ReadInfoHeader(BITMAPINFOHEADER*);
int CreatePalette(RGBQUAD);
int ReadPixelData(BYTE*);
LONG GetLineBytes(int,int);
int SaveAsImage(char*);
int main()
{
char saveasfilepath[256];
int i;
DWORD dwLineBytes;
readData();
dwLineBytes=GetLineBytes(bmih.biWidth,bmih.biBitCount);
N=(int)dwLineBytes*bmih.biHeight;
HistTrans();
printf("Save as another path(ex.d://poon.bmp)\n");
scanf("%s",saveasfilepath);
i=SaveAsImage(saveasfilepath);
if(i==-1)
{
printf("Error:failed to save the image.\n");
}
return 0;
}
void readData()
{
int i,k,h;
DWORD dwLineBytes;
i=ReadFileHeader(&bmfh);
if(i==0)
{
printf("Read file header successful!\n");
}
k=ReadInfoHeader(&bmih);
if(k==0)
{
printf("Read info header successful!\n");
}
dwLineBytes=GetLineBytes(bmih.biWidth,bmih.biBitCount);
imgData=(BYTE*)malloc(dwLineBytes*bmih.biHeight*sizeof(BYTE));
h=ReadPixelData(imgData);
if(h==0)
{
printf("Read pixel data successful!\n");
}
if(i==0&&k==0&&h==0)
{