搜索
bottom↓
回复: 13

RGB888转RGB565采用哪种算法比较能保证相近度?

[复制链接]

出0入0汤圆

发表于 2015-9-21 17:33:50 | 显示全部楼层 |阅读模式
比如:

1、RGB各自保证最小距离
2、像素点最小距离
3、相邻像素最小突变

最接近原始数据只是一方面,要能使图看着舒服也好。
图像处理没接触过,所知较少,还请斧正?

阿莫论坛20周年了!感谢大家的支持与爱护!!

阿莫论坛才是最爱国的,关心国家的经济、社会的发展、担心国家被别国牵连卷入战争、知道珍惜来之不易的和平发展,知道师夷之长,关注世界的先进文化与技术,也探讨中国文化的博大精深,也懂得警惕民粹主义的祸国殃民等等等等,无不是爱国忧民的表现。(坛友:tianxian)

出0入663汤圆

发表于 2015-9-21 17:36:40 | 显示全部楼层
简单的就直接取高位,想效果好点就加dither。

出0入0汤圆

发表于 2015-9-21 19:10:23 | 显示全部楼层
你百度一下RGB888和RGB565的格式,就知道怎么算了。

出0入0汤圆

发表于 2015-9-21 21:18:16 | 显示全部楼层
直接最高位不就完了,还有什么算法?

出0入663汤圆

发表于 2015-9-22 01:25:22 | 显示全部楼层
minrod_2012 发表于 2015-9-21 21:18
直接最高位不就完了,还有什么算法?

直接取高位会有色块感,最好是加dithering,这个需要算法的,不同的算法出来的效果不一样,耗费的运算周期也不同,需要看实际效果选择。
有的2D引擎自带硬件dithering,只要配置好寄存器就可以了。没有硬件加速的MCU算起来会很吃力,一般就直接截高位了。

出0入0汤圆

发表于 2015-9-22 11:04:28 | 显示全部楼层
试试这种抖动算法。
https://en.wikipedia.org/wiki/Ordered_dithering

============================================

/* Dither Tresshold for Red Channel */
static const BYTE dither_tresshold_r[64] = {
  1, 7, 3, 5, 0, 8, 2, 6,
  7, 1, 5, 3, 8, 0, 6, 2,
  3, 5, 0, 8, 2, 6, 1, 7,
  5, 3, 8, 0, 6, 2, 7, 1,

  0, 8, 2, 6, 1, 7, 3, 5,
  8, 0, 6, 2, 7, 1, 5, 3,
  2, 6, 1, 7, 3, 5, 0, 8,
  6, 2, 7, 1, 5, 3, 8, 0
};

/* Dither Tresshold for Green Channel */
static const BYTE dither_tresshold_g[64] = {
  1, 3, 2, 2, 3, 1, 2, 2,
  2, 2, 0, 4, 2, 2, 4, 0,
  3, 1, 2, 2, 1, 3, 2, 2,
  2, 2, 4, 0, 2, 2, 0, 4,

  1, 3, 2, 2, 3, 1, 2, 2,
  2, 2, 0, 4, 2, 2, 4, 0,
  3, 1, 2, 2, 1, 3, 2, 2,
  2, 2, 4, 0, 2, 2, 0, 4
};

/* Dither Tresshold for Blue Channel */
static const BYTE dither_tresshold_b[64] = {
  5, 3, 8, 0, 6, 2, 7, 1,
  3, 5, 0, 8, 2, 6, 1, 7,
  8, 0, 6, 2, 7, 1, 5, 3,
  0, 8, 2, 6, 1, 7, 3, 5,

  6, 2, 7, 1, 5, 3, 8, 0,
  2, 6, 1, 7, 3, 5, 0, 8,
  7, 1, 5, 3, 8, 0, 6, 2,
  1, 7, 3, 5, 0, 8, 2, 6
};

/* Get 16bit closest color */
BYTE closest_rb(BYTE c) {
  return (c >> 3 << 3); /* red & blue */
}
BYTE closest_g(BYTE c) {
  return (c >> 2 << 2); /* green */
}

/* RGB565 */
WORD RGB16BIT(BYTE r, BYTE g, BYTE b) {
  return ((WORD)((r>>3)<<11)|((g>>2)<<5)|(b>>3));
}

/* Dithering by individual subpixel */
WORD dither_xy(
  int x,
  int y,
  BYTE r,
  BYTE g,
  BYTE b
){
  /* Get Tresshold Index */
  BYTE tresshold_id = ((y & 7) << 3) + (x & 7);

  r = closest_rb(
          MIN(r + dither_tresshold_r[tresshold_id], 0xff)
       );
  g = closest_g(
          MIN(g + dither_tresshold_g[tresshold_id], 0xff)
       );
  b = closest_rb(
          MIN(b + dither_tresshold_b[tresshold_id], 0xff)
       );
  return RGB16BIT(r, g, b);
}

/* Dithering Pixel from 32/24bit RGB
*
* GetR, GetG, GetB -> Function to get individual color in pixel
*
*/
WORD dither_color_xy(int x, int y, DWORD col) {
  return dither_xy(x, y, GetR(col), GetG(col), GetB(col));
}

/* EXAMPLES */
void ExampleDither1(WORD * dest, DWORD * src, int width, int height){
  int x, y;
  for (y=0; y<height; y++){
    for (x=0; x<width; x++){
      int pos = y * width + x;
      dest[pos] = dither_color_xy(x,y,src[pos]);
    }
  }
}
void ExampleDither2(WORD * dest, BYTE * src, int width, int height){
  int x, y;
  for (y=0; y<height; y++){
    for (x=0; x<width; x++){
      int pos = y * width + x;
      dest[pos] = dither_xy(x,y,src[pos*3],src[pos*3+1],src[pos*3+2]);
    }
  }
}

出0入0汤圆

 楼主| 发表于 2015-9-22 11:09:58 | 显示全部楼层
okplay 发表于 2015-9-22 11:04
试试这种抖动算法。
https://en.wikipedia.org/wiki/Ordered_dithering

谢分享,配的图确实看出了明显的效果。

出0入0汤圆

 楼主| 发表于 2015-9-22 11:13:06 | 显示全部楼层
gzhuli 发表于 2015-9-22 01:25
直接取高位会有色块感,最好是加dithering,这个需要算法的,不同的算法出来的效果不一样,耗费的运算周 ...

我们可不用在MCU里二次处理,而是由PC软件预处理嘛。

出0入0汤圆

发表于 2019-9-15 06:29:01 | 显示全部楼层
我都是先用PS把图片处理成GIF格式

出0入0汤圆

发表于 2019-9-15 09:03:48 | 显示全部楼层
okplay 发表于 2015-9-22 11:04
试试这种抖动算法。
https://en.wikipedia.org/wiki/Ordered_dithering

看起来效果不错,MARK

出0入0汤圆

发表于 2019-9-15 12:12:20 | 显示全部楼层
okplay 发表于 2015-9-22 11:04
试试这种抖动算法。
https://en.wikipedia.org/wiki/Ordered_dithering

这个网址已经点不开了,难道被强了啊

出0入0汤圆

发表于 2019-9-15 12:27:09 来自手机 | 显示全部楼层
我也打不开了。
麻辣隔壁

出0入420汤圆

发表于 2024-8-8 10:47:32 | 显示全部楼层
okplay 发表于 2015-9-22 11:04
试试这种抖动算法。
https://en.wikipedia.org/wiki/Ordered_dithering

(引用自6楼)

不错,RGB888转RGB565抖动算法

出0入0汤圆

发表于 2024-8-9 00:53:37 来自手机 | 显示全部楼层
学习了,有空试试
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-9-17 18:24

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表