# Matlab处理彩色图像 RGB888-RGB565

1088人阅读 评论(0)

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的实现过程：

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
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：20560次
• 积分：601
• 等级：
• 排名：千里之外
• 原创：39篇
• 转载：6篇
• 译文：0篇
• 评论：15条
文章分类
阅读排行
评论排行
最新评论