简体   繁体   English

颜色偏移图像以匹配调色板

[英]color shift image to match a palette

在此处输入图像描述 I'd like to know if anyone knows about an algorithm that changes properties like saturation, color, brightness etc. of an Image, such that it matches a color palette, but also still looks good enough.我想知道是否有人知道一种算法,它可以改变图像的饱和度、颜色、亮度等属性,使其与调色板匹配,但看起来仍然足够好。

It would be nice if anyone could share any ideas on how to do that.如果有人可以分享有关如何做到这一点的任何想法,那就太好了。

My goal is to achieve a better result by doing this, when dithering the image, because my palette only contains 20 color.我的目标是在抖动图像时通过这样做来获得更好的结果,因为我的调色板只包含 20 种颜色。

When I used my simple C++ dithering on this input image(cropped from yours):当我在此输入图像上使用简单的 C++ 抖动(从您的图像中裁剪)时:

在图片中

And use distinct colors as palette from this:并使用不同的 colors 作为调色板:

在朋友

I got this output:我得到了这个 output:

抖动

The squares in top are the palette used looks like more than 20 colors to me... As you can see the output is much better than yours but your dithered result looks too pixelated is it downsampled and then zoomed?顶部的方块是使用的调色板,对我来说看起来超过 20 个 colors ......正如你所看到的 output 比你的要好得多,但你的抖动结果看起来太像素化了是它被降采样然后放大了吗?

Using just 2 shades of R,G,B,C,M,Y and 3 grayscales leads to 15 colors dithering:仅使用 2 种色调的 R,G,B,C,M,Y 和 3 灰度导致 15 colors 抖动:

15 种颜色

The more shades and combinations of RGB the better the result... Here all the combinations of 3 shades 3^3=27 colors: RGB 的阴影和组合越多,效果就越好...这里所有 3 种阴影的组合 3^3=27 colors:

27 种颜色

[Edit1] algorithm [Edit1] 算法

  1. handle each line of image separately分别处理每一行图像

    so process your image by horizontal or vertical lines.所以用水平线或垂直线处理你的图像。 You need to have a r0,g0,b0 signed temp variable set to zero before processing any line and palette pal[] holding your allowed colors.在处理任何包含允许的 colors 的行和调色板pal[]之前,您需要将r0,g0,b0带符号的临时变量设置为零。

  2. for each pixel (of processed line)对于每个像素(处理线)

    extract its r,g,b and add it to r0,g0,b0 , then find closest color to (r0,g0,b0) in your palette pal[] and substract chosen r,g,b from r0,g0,b0 .提取其r,g,b并将其添加到r0,g0,b0 ,然后在您的调色板pal[]中找到最接近(r0,g0,b0)的颜色,然后从 r0,g0,b0 中减去选择r,g,b r0,g0,b0

something like this:像这样的东西:

for (y=0;y<height;y++)
 {
 r0=0; g0=0; b0=0;
 for (x=0;x<width;x++)
  {
  // pick and add wanted color
  col=pixel(x,y);
  r0+=col.r;
  g0+=col.g;
  b0+=col.b;
  // chose closest color
  ix=0; col=(r0,g0,b0);
  for (i=0;i<palette_size;i++)
   if (color_distance(col,pal[i])<color_distance(col,pal[ix]))
    ix=i;
  col=pal[ix];
  // render and substract chosed color
  pixel(x,y)=col;
  r0-=col.r;
  g0-=col.g;
  b0-=col.b;
  }
 }

The choosing of closest color can be significantly speed up by LUT[r][g][b] table. LUT[r][g][b]表可以显着加快最接近颜色的选择。

This approach is fast and simple but far from best visually.这种方法既快速又简单,但远非最佳视觉效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM