Upload
dung-nguyen-duc
View
326
Download
0
Embed Size (px)
Citation preview
Computer Project for Chapter 11. (a) Obtain a set of YCrCb images for the set of 256x256 RGB Lena
Images (Lena256C.bmp is a color input image) (b) Obtain a set of HIS images for the set of RGB images
2. Obtain images subsampled with (2:1)x(2:1), (4:1)x(4:1) from 512x512 Lena image. Display the original image and the subsampled ones with the same size and compare their qualities (Le512.raw is a gray input image).
3. Obtain 1-, 2-, 4-, 6-bit images from 8-bit 512x512 Lena image. Display the original image and the outputs, and compare their qualities (Le512.raw is a gray input image).
Note: 1. Lena256C is a bitmap color image. You should read it out in your program using the following referenced function in C++, and then RGB images will be stored in * * * array for further processing
======unsigned char*** ReadRGB(char *str, int &height, int &width, int &bit)
{
unsigned char ***rgb=NULL;
FILE *fp;
if((fp=fopen(str,"rb"))==NULL)
{
// AfxMessageBox("file open error");
return(rgb);
}
BITMAPFILEHEADER bmpfileheader;
fread(&bmpfileheader,sizeof(BITMAPFILEHEADER),1,fp);
BITMAPINFOHEADER bmpinfoheader;
fread(&bmpinfoheader,sizeof(BITMAPINFOHEADER),1,fp);
bit=bmpinfoheader.biBitCount;
int byte_count=bit/8;
height=bmpinfoheader.biHeight;
width=bmpinfoheader.biWidth;
if(bit!=24&&bit!=8)
{
// AfxMessageBox("No 8bit or 24bit image!.");
fclose(fp);
return(rgb);
}
rgb=(unsigned char***)malloc(byte_count*sizeof(unsigned char**));
for(int i=0;i<byte_count;i++)
{
rgb[i]=(unsigned char**)malloc(height*sizeof(unsigned char*));
for(int y=0;y<height;y++)
rgb[i][y]=(unsigned char*)malloc(width);
}
for(int y=0;y<height;y++)
for(int x=0;x<width;x++)
{
for(i=0;i<byte_count;i++)
{
rgb[byte_count-i-1][x][y]=getc(fp);
}
}
fclose(fp);
return(rgb);
}======2. Lena.raw is a 8-bit gray scale image. You may refer the following code:======float x[256][256], y[256][256]; //x array for in put, y array for outputFILE *fo ,*fs ; int i,j; fo=fopen("lena.raw","rb");//for reading raw image for(i=0;i<256;i++) { for(j=0; j<256; j++) { x[i][j]=(float)getc(fo); } }fs=fopen("output.raw","wb");// for writing raw image for(i=0;i<256;i++) {
for(j=0;j<256;j++) { putc((unsigned char)y[i][j],fs); } } }