Exemplo n.º 1
0
        public static FlatMatrix <int> GetSubMatrix(this FlatMatrix <int> matrix, int x, int y, int width, int height, int cellSize)
        {
            width  /= cellSize;
            height /= cellSize;

            var subMatrix = new FlatMatrix <int>(width, height);

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    var average = 0;

                    for (var k = 0; k < cellSize; k++)
                    {
                        for (var l = 0; l < cellSize; l++)
                        {
                            average += matrix[x + i * cellSize + k, y + j * cellSize + l];
                        }
                    }

                    average /= cellSize * cellSize;

                    subMatrix[i, j] = average;
                }
            }

            return(subMatrix);
        }
Exemplo n.º 2
0
 public Image(int width, int height)
 {
     Width  = width;
     Height = height;
     X      = new FlatMatrix <Type>(width, height);
     Y      = new FlatMatrix <Type>(width, height);
     Z      = new FlatMatrix <Type>(width, height);
 }
Exemplo n.º 3
0
 public Image(Image image)
 {
     Width  = image.Width;
     Height = image.Height;
     X      = new FlatMatrix <Type>(image.X);
     Y      = new FlatMatrix <Type>(image.Y);
     Z      = new FlatMatrix <Type>(image.Z);
 }
Exemplo n.º 4
0
 public static void SetSubMatrix(this FlatMatrix <int> matrix, int x, int y, FlatMatrix <int> subMatrix, int cellSize)
 {
     for (var i = 0; i < subMatrix.Width; i++)
     {
         for (var j = 0; j < subMatrix.Height; j++)
         {
             for (var k = 0; k < cellSize; k++)
             {
                 for (var l = 0; l < cellSize; l++)
                 {
                     matrix[x + i * cellSize + k, y + j * cellSize + l] = subMatrix[i, j];
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        private static ImageBlocks ToBlocks(Image image)
        {
            var imageBlocks = new ImageBlocks(image.Width, image.Height);

            for (var i = 0; i < image.Width; i += Block.Size)
            {
                for (var j = 0; j < image.Height; j += Block.Size)
                {
                    FlatMatrix <int> y = image.X.GetSubMatrix(i, j, Block.Size, Block.Size);
                    FlatMatrix <int> u = image.X.GetSubMatrix(i, j, Block.Size, Block.Size, 2);
                    FlatMatrix <int> v = image.X.GetSubMatrix(i, j, Block.Size, Block.Size, 2);

                    var yBlock = new Block
                    {
                        Position = (i, j),
                        Type     = BlockType.Y,
                        Values   = y
                    };

                    var uBlock = new Block
                    {
                        Position = (i, j),
                        Type     = BlockType.U,
                        Values   = u
                    };

                    var vBlock = new Block
                    {
                        Position = (i, j),
                        Type     = BlockType.V,
                        Values   = v
                    };

                    imageBlocks.Blocks.Add(yBlock);
                    imageBlocks.Blocks.Add(uBlock);
                    imageBlocks.Blocks.Add(vBlock);
                }
            }

            return(imageBlocks);
        }
    }
}