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
        private static List <PixelYRGB> GeneratePCRDataForGreyImage(Bitmap bmp)
        {
            List <PixelYRGB> imageData = new List <PixelYRGB>();

            // Really make sure its greyscale
            Bitmap greyBMP = Coloring.ConvertToGrayscale(bmp);
            //greyBMP.Save(@"C:\Temp\SamplesImages\color\v3\GreyConvertedToGrey.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);

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

                    imageData.Add(pcr);
                }
            }

            return(imageData);
        }