# Matlab处理彩色图像 RGB888-RGB565

image=imread('E:\64c.bmp');
fr=image(:,:,1);
fg=image(:,:,2);

fb=image(:,:,3);

“著作权归作者所有。

 0 0 0 0 0 0 0 0 R7 R6 R5 R4 R3 R2 R1 R0 G7 G6 G5 G4 G3 G2 G1 G0 B7 B6 B5 B4 B3 B2 B1 B0

 R7 R6 R5 R4 R3 G7 G6 G5 G4 G3 G2 B7 B6 B5 B4 B3

#define RGB888_RED      0x00ff0000
#define RGB888_GREEN    0x0000ff00
#define RGB888_BLUE     0x000000ff

#define RGB565_RED      0xf800
#define RGB565_GREEN    0x07e0
#define RGB565_BLUE     0x001f

unsigned short RGB888ToRGB565(unsigned int n888Color)
{
unsigned short n565Color = 0;

// 获取RGB单色，并截取高位
unsigned char cRed   = (n888Color & RGB888_RED)   >> 19;
unsigned char cGreen = (n888Color & RGB888_GREEN) >> 10;
unsigned char cBlue  = (n888Color & RGB888_BLUE)  >> 3;

// 连接
n565Color = (cRed << 11) + (cGreen << 5) + (cBlue << 0);
return n565Color;
}

unsigned int RGB565ToRGB888(unsigned short n565Color)
{
unsigned int n888Color = 0;

// 获取RGB单色，并填充低位
unsigned char cRed   = (n565Color & RGB565_RED)    >> 8;
unsigned char cGreen = (n565Color & RGB565_GREEN)  >> 3;
unsigned char cBlue  = (n565Color & RGB565_BLUE)   << 3;

// 连接
n888Color = (cRed << 16) + (cGreen << 8) + (cBlue << 0);
return n888Color;
Matlab的实现过程：

image=imread('E:\64c.bmp');
fr=image(:,:,1);
fg=image(:,:,2);
fb=image(:,:,3);
ar=fr*(31/255);
ag=fg*(63/255);
ab=fb*(31/255);
%imgR = uint8((255/31)*bitshift(bitand(fr,63488),-11));  %# Red component
%imgG = uint8((255/63)*bitshift(bitand(fg,2016),-5));    %# Green component
%imgB = uint8((255/31)*bitand(fb,31));                   %# Blue component

08-28 544

05-23 1083

01-20 7289

05-09 60

03-31 2.2万

12-27 5407

#### Matlab中常用颜色的RGB值表

2016年12月29日 502KB 下载

05-13 2705

01-29 1.5万

12-01 7283