public void getRGBData(ColorHistogram colorHist, double[][] data)
        {
            int size = colorHist.getNumberOfColors();

            for (int x = 0; x < size; x++)
            {
                data[x] = new double[3];
                int rgb = colorHist.getColor(x);
                data[x][0] = ((rgb & 0xFF0000) >> 16);
                data[x][1] = ((rgb & 0xFF00) >> 8);
                data[x][2] = (rgb & 0xFF);
            }
        }
        public void getYIQData(ColorHistogram colorHist, double[][] data)
        {
            int size = colorHist.getNumberOfColors();

            for (int x = 0; x < size; x++)
            {
                data[x] = new double[3];
                int      rgb = colorHist.getColor(x);
                double[] yiq = RGB2YIQ(rgb);

                for (int y = 0; y < 3; y++)
                {
                    data[x][y] = yiq[y];
                }
            }
        }
        public string Apply(int k, string fn, string outImagePath)
        {
            Bitmap srcimg = new Bitmap(fn);

            pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
            ColorHistogram colorHist = new ColorHistogram(pixels, false);
            int            size      = colorHist.getNumberOfColors();

            if (size <= k)
            {
                srcimg.Save(outImagePath, ImageFormat.Png);
            }
            else
            {
                double[][] data = new double[size][];

                getRGBData(colorHist, data);
                ClusterCollection clusters;
                KMeansParallel    kMeans = new KMeansParallel();
                clusters = kMeans.ClusterDataSet(k, data);
                PaintRGB(srcimg, kMeans, clusters).Save(outImagePath, ImageFormat.Png);
            }
            return(outImagePath);
        }