100 likes | 219 Views
Digital Image Processing. Kim Nam Woo. Bitmap-File & Raw-File. Structure(1). #include <stdio.h> void main() { int i, j; unsigned char OrgImg[256][256]; FILE *infile = fopen("coin.raw","rb"); if(infile==NULL) { printf("File open error !!"); return; }
E N D
Digital Image Processing Kim Nam Woo
Bitmap-File & Raw-File Digital Image Processing, Kim Nam Woo, Dongseo Univ.
Structure(1) #include <stdio.h> void main() { int i, j; unsigned char OrgImg[256][256]; FILE *infile = fopen("coin.raw","rb"); if(infile==NULL) { printf("File open error !!"); return; } fread(OrgImg,sizeof(char),256*256,infile); fclose(infile); for(i=0; i<256; i++) { for(j=0; j<256; j++) { OrgImg[i][j] = 255-OrgImg[i][j]; } } FILE *outfile = fopen("coin_inv.raw","wb"); fwrite(OrgImg,sizeof(char),256*256,outfile); fclose(outfile); } Digital Image Processing, Kim Nam Woo, Dongseo Univ.
Structure(2) BYTE *lpImg = new BYTE [hInfo.biSizeImage]; fread(lpImg,sizeof(char),hInfo.biSizeImage,infile); fclose(infile); int rwsize = WIDTHBYTES(hInfo.biBitCount*hInfo.biWidth); for(int i=0; i<hInfo.biHeight; i++) { for(int j=0; j<hInfo.biWidth; j++) { lpImg[i*rwsize+j] = 255-lpImg[i*rwsize+j]; } } FILE *outfile = fopen("OutImg.bmp","wb"); fwrite(&hf,sizeof(char),sizeof(BITMAPFILEHEADER),outfile); fwrite(&hInfo,sizeof(char),sizeof(BITMAPINFOHEADER),outfile); fwrite(hRGB,sizeof(RGBQUAD),256,outfile); fwrite(lpImg,sizeof(char),hInfo.biSizeImage,outfile); fclose(outfile); delete []lpImg; } #include <stdio.h> #include <windows.h> #define WIDTHBYTES(bits) (((bits)+31)/32*4) #define BYTE unsigned char void main() { FILE *infile; infile=fopen("talent.bmp", "rb"); if(infile==NULL) { printf("There is no file!!!\n"); exit(1); } BITMAPFILEHEADER hf; fread(&hf,sizeof(BITMAPFILEHEADER),1,infile); if(hf.bfType!=0x4D42) exit(1); BITMAPINFOHEADER hInfo; fread(&hInfo,sizeof(BITMAPINFOHEADER),1,infile); printf("Image Size: (%3dx%3d)\n",hInfo.biWidth,hInfo.biHeight); printf("Pallete Type: %dbit Colors\n",hInfo.biBitCount); if(hInfo.biBitCount!=8 ) { printf("Bad File format!!"); exit(1); } RGBQUAD hRGB[256]; fread(hRGB,sizeof(RGBQUAD),256,infile); Digital Image Processing, Kim Nam Woo, Dongseo Univ.
Color 특징 • 8bit color • 각 픽셀이 1바이트의 R,G,B 값 중에 하나를 가짐 • 픽셀 자체가 색상정보를 가지고 있지 않기 때문에 팔레트 필요 • 출력 속도가 빠름 • 24bit color • 각 픽셀이 3바이트의 R,G,B 조합의 값으로 이루어져 있음 • 픽셀 자체가 색상정보를 가지고 있기 때문에 팔레트가 필요 없음 • 데이터의 용량이 커지고 출력속도가 느림 Digital Image Processing, Kim Nam Woo, Dongseo Univ.
Bitmap-File 구조 Digital Image Processing, Kim Nam Woo, Dongseo Univ.
BITMAPFILEHEADER typedef struct tagBITMAPFILEHEADER { WORD bfType; WORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER; Digital Image Processing, Kim Nam Woo, Dongseo Univ.
BITMAPINFOHEADER typedef struct tagBITMAPINFOHEADER { DWORD biSize; LONG biWidth; LONG biHeitht; WORD biplanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; }BITMAPINFOHEADER; Digital Image Processing, Kim Nam Woo, Dongseo Univ.
RGBQUAD tydef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; }RGBQUAD; Digital Image Processing, Kim Nam Woo, Dongseo Univ.