Example #1
0
        private List <PixelYUV> GenerateYUVCRDataForColorImage(Bitmap bmp)
        {
            List <PixelYUV> imageData = new List <PixelYUV>();
            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[greyCImg.Height][];
            for (int y = 0; y < bmp.Height; y++)
            {
                lumGrid[y] = new double[greyCImg.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 yuvRow = new PixelYUV()
                    {
                        Y = lumGrid[y2][x2],
                        NeighbourMeanLuminance = mean,
                        NeighbourLuminanceStandardDeviation = Utilities.GetStandardDeviationofNeighbours(neighbours, mean, false),
                    };

                    var tempYUV = new RGB(
                        colorCImg.Grid[3 * i2 + 2],
                        colorCImg.Grid[3 * i2 + 1],
                        colorCImg.Grid[3 * i2 + 0]).ToYUV();

                    yuvRow.U = (float)tempYUV.U;
                    yuvRow.V = (float)tempYUV.V;

                    imageData.Add(yuvRow);
                }
            }

            return(imageData);
        }
Example #2
0
        public void Shuffle(ref List <PixelYUV> list)
        {
            Random rng = new Random();
            int    n   = list.Count;

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