How to implement 24bit to 3bit ordered dither algorithm?

人盡茶涼 提交于 2020-01-25 02:50:47

问题


I am attempting to implement a Bayer ordered dithering matrix algorithm to convert a 24bit color image to a 3bit image. I have read the Wikipedia page, and several textbook sections on the topic and am a bit confused. This is what I have so far:

for (int y = 0; x < image.Height; y++)
{  
    for (int x = 0; x < image.Width; x++)
    {
        Color color = image.GetPixel(x,y);  
        color.R = color.R + bayer4x4[x % 4, y % 4];  
        color.G = color.G + bayer4x4[x % 4, y % 4];  
        color.B = color.B + bayer4x4[x % 4, y % 4];  
        image[x][y] = SetPixel(x, y, GetClosestColor(color, bitdepth);  
    }  
}

However, I do not have a way of implementing GetClosestColor... how can I do this?

Also, I do not have the bayer4x4 matrix defined, I believe it should look like the following:

1,  9,  3, 11
13, 5, 15, 7
4, 12,  2, 10
16, 8, 14, 6

来源:https://stackoverflow.com/questions/36087038/how-to-implement-24bit-to-3bit-ordered-dither-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!