Пример #1
0
        private List <PixelYRGB> GeneratePCRDataForColorImage(Bitmap bmp)
        {
            List <PixelYRGB> imageData = new List <PixelYRGB>();
            CImage           colorCImg = new CImage(bmp);

            Bitmap greyBMP = Coloring.ConvertToGrayscale(bmp);
            //greyBMP.Save(@"C:\Temp\SamplesImages\color\v3\ColoredConvertedToGrey.jpg");
            CImage greyCImg = new CImage(greyBMP);

            greyBMP.Dispose();

            // Populate LumGrid
            double[][] lumGrid = new double[colorCImg.Height][];
            for (int y = 0; y < bmp.Height; y++)
            {
                lumGrid[y] = new double[colorCImg.Width];
                for (int x = 0; x < bmp.Width; x++)
                {
                    int i = (x + (bmp.Width * y));
                    lumGrid[y][x] = Utilities.CalcLuminance(
                        greyCImg.Grid[3 * i + 2],   // R
                        greyCImg.Grid[3 * i + 1],   // G
                        greyCImg.Grid[3 * i + 0]    // B
                        );
                }
            }

            // Populate imageData
            for (int y2 = 0; y2 < bmp.Height; y2++)
            {
                for (int x2 = 0; x2 < bmp.Width; x2++)
                {
                    // get neighbours
                    double[] neighbours = Utilities.GetCardinalNeighbours(ref lumGrid, x2, y2);
                    double   mean       = Utilities.GetMeanOfNeighbours(neighbours);
                    int      i2         = (x2 + (bmp.Width * y2));

                    var pcr = new PixelYRGB()
                    {
                        Y = lumGrid[y2][x2],
                        NeighbourMeanLuminance = mean,
                        NeighbourLuminanceStandardDeviation = Utilities.GetStandardDeviationofNeighbours(neighbours, mean, false),
                    };

                    pcr.R = colorCImg.Grid[3 * i2 + 2]; // R
                    pcr.G = colorCImg.Grid[3 * i2 + 1]; // G
                    pcr.B = colorCImg.Grid[3 * i2 + 0]; // B

                    imageData.Add(pcr);
                }
            }

            return(imageData);
        }
Пример #2
0
        public void Shuffle(ref List <PixelYRGB> list)
        {
            Random rng = new Random();
            int    n   = list.Count;

            while (n > 1)
            {
                n--;
                int       k     = rng.Next(n + 1);
                PixelYRGB value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }