有没有一种方法可以从数组中获取最常见的项并排除双项?

对于一个项目,我需要将图像的颜色从24bit减少到8bit。

我想创建一个可以在图像中找到256种最常用颜色的函数,这样我就可以在新的调色板中使用这些颜色并对图像进行一些颜色量化

我已经有一个可以从图像中读取像素颜色的功能

public static byte[] Owngetcolordata(Bitmap bmp)
        {
            int height = bmp.Height;
            int width = bmp.Width;
            int res = height * width;
            var colors = new List<List<byte>>();
            var pixelColor = new List<byte>();
            Color c;

            for (int x = 0; x < bmp.Height; x++)
            {
                for(int y = 0; y< bmp.Width; y++)
                {
                    c = bmp.GetPixel(x,y);

                    pixelColor.Add(c.R);
                    pixelColor.Add(c.G);
                    pixelColor.Add(c.B);

                    colors.Add(pixelColor);
                    pixelColor.Clear();
                }
            }
            return pixelColor.ToArray();
        }

此函数的输出是一个二维数组,在每个像素索引上都有一个RGB数组。例如:在索引0上是具有数组(255,255,255)的像素1

salanganeyuhaiyan 回答:有没有一种方法可以从数组中获取最常见的项并排除双项?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3165332.html

大家都在问