Î÷°²½»´óÊý×ÖͼÏñ´¦ÀíµÚÒ»´Î×÷Òµ ÏÂÔر¾ÎÄ

Êý×ÖͼÏñ´¦ÀíµÚÒ»´Î×÷Òµ

ÐÕÃû£º °à¼¶£º ѧºÅ£º

Ìá½»ÈÕÆÚ£º2015Äê3ÔÂ13ÈÕ

ÕªÒª

±¾´Î±¨¸æÊ×Ïȼòµ¥²ûÊöÁËBMPͼÏñ¸ñʽ¼°ÆäÏà¹ØÊý¾Ý½á¹¹£¬ËæºóÖ÷ÒªÍê³ÉÁË×÷ÒµÒªÇóÖйØÓÚͼÏñ´¦ÀíÓë¼ÆËãµÄ¸÷ÏîÈÎÎñ¡£±¾´Î×÷ÒµÒÔMatlab 2014Ϊƽ̨£¬Í¨¹ý¶Ôlena.bmp,elain.bmpͼÏñÎļþµÄ±à³Ì´¦Àí£¬·Ö±ðµÃµ½ÁËlena.bmpͼÏñµÄ8µ½1¼¶»Ò¶ÈÖ𼶵ݼõÏÔʾ£¬lena.bmpͼÏñµÄ¾ùÖµºÍ·½²î£¬Í¨¹ý½üÁÚ¡¢Ë«ÏßÐÔºÍË«Èý´Î²åÖµ·¨¶Ôlena.bmp½øÐÐ4±¶·Å´óºóµÃµ½µÄ2048¡Á2048³ß´çͼÏñ£¬ºÍ¶Ôlena.bmp¡¢elain.bmpͼÏñ·Ö±ð½øÐÐˮƽƫÒƱ任ºÍÐýת±ä»»ºóµÄͼÏñ¼°Æä4±¶²åÖµ·Å´óͼÏñ¡£ÒÔÉÏÈÎÎñÍê³Éºó¾ùµÃµ½ÁËÔ¤ÆڵĽá¹û¡£

1.BmpͼÏñ¸ñʽ¼ò½é¡£ 1.1 BMP¸ñʽ¸ÅÊö

BMP£¨È«³ÆBitmap£©ÊÇWindows²Ù×÷ϵͳÖеıê׼ͼÏñÎļþ¸ñʽ£¬¿ÉÒÔ·Ö³ÉÁ½ÀࣺÉ豸Ïà¹Øλͼ£¨DDB£©ºÍÉ豸ÎÞ¹Øλͼ£¨DIB£©£¬Ê¹Ó÷dz£¹ã¡£Ëü²ÉÓÃλӳÉä´æ´¢¸ñʽ£¬³ýÁËͼÏñÉî¶È¿ÉÑ¡ÒÔÍ⣬²»²ÉÓÃÆäËûÈκÎѹËõ£¬Òò´Ë£¬BMPÎļþËùÕ¼ÓõĿռäºÜ´ó¡£BMPÎļþµÄͼÏñÉî¶È¿ÉÑ¡lbit¡¢4bit¡¢8bit¼°24bit¡£BMPÎļþ´æ´¢Êý¾Ýʱ£¬Í¼ÏñµÄɨÃ跽ʽÊÇ°´´Ó×óµ½ÓÒ¡¢´Óϵ½ÉϵÄ˳Ðò¡£ 1.2 BMP¸ñʽ×é³É

µäÐ͵ÄBMPͼÏñÎļþÓÉËIJ¿·Ö×é³É£º

£¨1£©Î»Í¼Í·ÎļþÊý¾Ý½á¹¹£¬Ëü°üº¬BMPͼÏñÎļþµÄÀàÐÍ¡¢ÏÔʾÄÚÈݵÈÐÅÏ¢£»

£¨2£©Î»Í¼ÐÅÏ¢Êý¾Ý½á¹¹£¬Ëü°üº¬ÓÐBMPͼÏñµÄ¿í¡¢¸ß¡¢Ñ¹Ëõ·½·¨£¬ÒÔ¼°¶¨ÒåÑÕÉ«µÈÐÅÏ¢£» £¨3£©µ÷É«°å£¬Õâ¸ö²¿·ÖÊÇ¿ÉÑ¡µÄ£¬ÓÐЩλͼÐèÒªµ÷É«°å£¬ÓÐЩλͼ£¬±ÈÈçÕæ²Êɫͼ£¨24λµÄBMP£©¾Í²»ÐèÒªµ÷É«°å£»

£¨4£©Î»Í¼Êý¾Ý£¬Õⲿ·ÖµÄÄÚÈݸù¾ÝBMPλͼʹÓõÄλÊý²»Í¬¶ø²»Í¬£¬ÔÚ24λͼÖÐÖ±½ÓʹÓÃRGB£¬¶øÆäËûµÄСÓÚ24λµÄʹÓõ÷É«°åÖÐÑÕÉ«Ë÷ÒýÖµ¡£ 1.3 BMP¸ñʽ¶ÔÓ¦Êý¾Ý½á¹¹

BMPÎļþÓÉÎļþÍ·¡¢Î»Í¼ÐÅϢͷ¡¢ÑÕÉ«ÐÅÏ¢ºÍͼÐÎÊý¾ÝËIJ¿·Ö×é³É¡£ 1.3.1 BMPÎļþÍ·£¨14×Ö½Ú£©

BMPÎļþÍ·Êý¾Ý½á¹¹º¬ÓÐBMPÎļþµÄÀàÐÍ¡¢Îļþ´óСºÍλͼÆðʼλÖÃµÈ ÐÅÏ¢¡£ Æä½á¹¹¶¨ÒåÈçÏ£º

typedef struct tagBITMAPFILEHEADER {

WORD bfType; // λͼÎļþµÄÀàÐÍ£¬±ØÐëΪBM(1-2×Ö½Ú£©

DWORD bfSize; // λͼÎļþµÄ´óС£¬ÒÔ×Ö½ÚΪµ¥Î»£¨3-6×Ö½Ú£© WORD bfReserved1; // λͼÎļþ±£Áô×Ö£¬±ØÐëΪ0(7-8×Ö½Ú£© WORD bfReserved2; // λͼÎļþ±£Áô×Ö£¬±ØÐëΪ0(9-10×Ö½Ú£©

DWORD bfOffBits; // λͼÊý¾ÝµÄÆðʼλÖã¬ÒÔÏà¶ÔÓÚλͼ£¨11-14×Ö½Ú£© // ÎļþÍ·µÄÆ«ÒÆÁ¿±íʾ£¬ÒÔ×Ö½ÚΪµ¥Î» } BITMAPFILEHEADER; 1.3.2 λͼÐÅϢͷ£¨40×Ö½Ú£©

BMPλͼÐÅϢͷÊý¾ÝÓÃÓÚ˵Ã÷λͼµÄ³ß´çµÈÐÅÏ¢¡£ typedef struct tagBITMAPINFOHEADER{

DWORD biSize; // ±¾½á¹¹ËùÕ¼ÓÃ×Ö½ÚÊý£¨15-18×Ö½Ú£©

LONG biWidth; // λͼµÄ¿í¶È£¬ÒÔÏñËØΪµ¥Î»£¨19-22×Ö½Ú£© LONG biHeight; // λͼµÄ¸ß¶È£¬ÒÔÏñËØΪµ¥Î»£¨23-26×Ö½Ú£© WORD biPlanes; // Ä¿±êÉ豸µÄ¼¶±ð£¬±ØÐëΪ1(27-28×Ö½Ú£©

WORD biBitCount;// ÿ¸öÏñËØËùÐèµÄλÊý£¬±ØÐëÊÇ1£¨Ë«É«£©£¬£¨29-30×Ö½Ú£© // 4(16É«£©£¬8(256É«£©16(¸ß²ÊÉ«)»ò24£¨Õæ²ÊÉ«£©Ö®Ò»

DWORD biCompression; // λͼѹËõÀàÐÍ£¬±ØÐëÊÇ 0£¨²»Ñ¹Ëõ£©£¬£¨31-34×Ö½Ú£© // 1(BI_RLE8ѹËõÀàÐÍ£©»ò2(BI_RLE4ѹËõÀàÐÍ£©Ö®Ò»

DWORD biSizeImage; // λͼµÄ´óС(ÆäÖаüº¬ÁËΪÁ˲¹ÆëÐÐÊýÊÇ4µÄ±¶Êý¶øÌí¼ÓµÄ¿Õ×Ö½Ú)£¬ÒÔ×Ö½ÚΪµ¥Î»£¨35-38×Ö½Ú£©

LONG biXPelsPerMeter; // λͼˮƽ·Ö±æÂÊ£¬Ã¿Ã×ÏñËØÊý£¨39-42×Ö½Ú£© LONG biYPelsPerMeter; // λͼ´¹Ö±·Ö±æÂÊ£¬Ã¿Ã×ÏñËØÊý£¨43-46×Ö½Ú)

DWORD biClrUsed;// λͼʵ¼ÊʹÓõÄÑÕÉ«±íÖеÄÑÕÉ«Êý£¨47-50×Ö½Ú£© DWORD biClrImportant;// λͼÏÔʾ¹ý³ÌÖÐÖØÒªµÄÑÕÉ«Êý£¨51-54×Ö½Ú£© } BITMAPINFOHEADER; 1.3.3 ÑÕÉ«±í

ÑÕÉ«±íÓÃÓÚ˵Ã÷λͼÖеÄÑÕÉ«£¬ËüÓÐÈô¸É¸ö±íÏÿһ¸ö±íÏîÊÇRGBQUADÀàÐ͵Ľṹ£¬¶¨ÒåÒ»ÖÖÑÕÉ«¡£RGBQUAD½á¹¹µÄ¶¨ÒåÈçÏ£º

typedef struct tagRGBQUAD {

BYTE rgbBlue;// À¶É«µÄÁÁ¶È£¨Öµ·¶Î§Îª0-255) BYTE rgbGreen; // ÂÌÉ«µÄÁÁ¶È£¨Öµ·¶Î§Îª0-255) BYTE rgbRed; // ºìÉ«µÄÁÁ¶È£¨Öµ·¶Î§Îª0-255) BYTE rgbReserved;// ±£Áô£¬±ØÐëΪ0 } RGBQUAD;

ÑÕÉ«±íÖÐRGBQUAD½á¹¹Êý¾ÝµÄ¸öÊýÓÐbiBitCountÀ´È·¶¨£º µ±biBitCount=1,4,8ʱ£¬·Ö±ðÓÐ2,16,256¸ö±íÏ µ±biBitCount=24ʱ£¬Ã»ÓÐÑÕÉ«±íÏî¡£

λͼÐÅϢͷºÍÑÕÉ«±í×é³ÉλͼÐÅÏ¢£¬BITMAPINFO½á¹¹¶¨ÒåÈçÏ£º typedef struct tagBITMAPINFO {

BITMAPINFOHEADER bmiHeader; // λͼÐÅϢͷ RGBQUAD bmiColors[1]; // ÑÕÉ«±í } BITMAPINFO; 1.3.4 λͼÊý¾Ý

λͼÊý¾Ý¼Ç¼ÁËλͼµÄÿһ¸öÏñËØÖµ£¬¼Ç¼˳ÐòÊÇÔÚɨÃèÐÐÄÚÊÇ´Ó×óµ½ÓÒ£¬ ɨÃèÐÐÖ®¼äÊÇ´Óϵ½ÉÏ¡£Î»Í¼µÄÒ»¸öÏñËØÖµËùÕ¼µÄ×Ö½ÚÊý£º

µ±biBitCount=1ʱ£¬8¸öÏñËØÕ¼1¸ö×Ö½Ú£» µ±biBitCount=4ʱ£¬2¸öÏñËØÕ¼1¸ö×Ö½Ú£» µ±biBitCount=8ʱ£¬1¸öÏñËØÕ¼1¸ö×Ö½Ú£»

µ±biBitCount=24ʱ£¬1¸öÏñËØÕ¼3¸ö×Ö½Ú,°´Ë³Ðò·Ö±ðΪB,G,R£»

Windows¹æ¶¨Ò»¸öɨÃèÐÐËùÕ¼µÄ×Ö½ÚÊý±ØÐëÊÇ4µÄ±¶Êý£¨¼´ÒÔlongΪµ¥Î»£©£¬ ²»×ãµÄÒÔ0Ìî³ä¡£

2.°Ñlena512*512ͼÏñ»Ò¶È¼¶Ö𼶵ݼõ8-1ÏÔʾ¡£

£¨1£©ÎÊÌâ·ÖÎö£º±¾ÌâÖжÔͼÏñ½øÐеIJÙ×÷ÊÇÖ±½Ó»Ò¶È±ä»»¡£Ê×ÏÈÀûÓÃimreadº¯Êý¶ÁÈë lena512.bmp£¬µÃµ½Í¼ÏñµÄ»Ò¶È¾ØÕóI£¬Ö®ºó¶Ô»Ò¶È¾ØÕóÖеÄÿ¸öÔªËؽøÐвÙ×÷£¬¼´Õó ÁвÙ×÷¡£½«»Ò¶È¾ØÕóµÄÿ¸öÔªËØÖµ³ýÒÔ¶þ£¬È¡Õûºó½«½á¹ûת»»ÎªÎÞ·ûºÅ8λÊý£¬¼ÈµÃ µ½»Ò¶È¼¶Îª7µÄͼÏñ£¬×îºóÀûÓÃimshowº¯ÊýÊä³öÏÔʾͼÏñ¡£Í¬Àí¿ÉµÃµ½»Ò¶È¼¶Îª6-1 µÄͼÏñ¡£¶ÔÓ¦Ô´³ÌÐòlena.m £¨2£©MATLABº¯Êý£º

A=imread£¨¡®filename¡¯£©

ÓÃimreadº¯Êý¶ÁȡͼÏñÎļþ£¬Îļþ¸ñʽ¿ÉÒÔÊÇTIFF¡¢JPEG¡¢GIF¡¢BMP¡¢PNG¡£ ¶Á½øÀ´µÄÊÇÒ»¸ö¶þάÊý×飬´æ·ÅÔÚ¾ØÕóAÖС£ µ÷Óøñʽ£º

A=imread(filename,fmt)

[X,map]=imread(filename,fmt) imshow(A)