Ejemplo n.º 1
0
        private Standart InitStandart(Bitmap bmp)
        {
            var idealStandart = new IdealStandart();
            idealStandart.Matrix = new bool[bmp.Width, bmp.Height];
            idealStandart.Height = bmp.Height;
            idealStandart.Width = bmp.Width;
            var mask = new Mask();
            mask.Matrix = new bool[bmp.Width, bmp.Height];
            mask.Height = bmp.Height;
            mask.Width = bmp.Width;

            var incedenceMatrix = new int[bmp.Height][];

            unsafe
            {
                BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite,
                    bmp.PixelFormat);

                int bytesPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat)/8;
                int heightInPixels = bitmapData.Height;
                int widthInBytes = bitmapData.Width*bytesPerPixel;
                var ptrFirstPixel = (byte*) bitmapData.Scan0;

                for (int y = 0; y < heightInPixels; y++)
                {
                    var maskRow = new bool[bmp.Width];
                    var standartRow = new bool[bmp.Width];

                    byte* currentLine = ptrFirstPixel + (y*bitmapData.Stride);
                    for (int x = 0, cell = 0; x < widthInBytes; x = x + bytesPerPixel, cell++)
                    {
                        int blue = currentLine[x];
                        int green = currentLine[x + 1];
                        int red = currentLine[x + 2];
                        maskRow[cell] =
                            mask.Matrix[cell, y] = red > 0 && blue + green == 0 || green > 0 && blue + red == 0;
                        standartRow[cell] =
                            idealStandart.Matrix[cell, y] = red + green + blue == 0 || red > 0 && blue + green == 0;
                    }

                    incedenceMatrix[y] = IncedenceMatrixRowFill(maskRow, standartRow);
                }
                bmp.UnlockBits(bitmapData);
            }
            idealStandart.IncidenceMatrix = incedenceMatrix;

            return new Standart(mask, idealStandart);
        }
Ejemplo n.º 2
0
 public Standart(Mask mask, IdealStandart standart)
 {
     Mask = mask;
     IdealStandart = standart;
 }