コード例 #1
0
ファイル: Extensions.cs プロジェクト: caprapaul/assignments
        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);
        }
コード例 #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);
 }
コード例 #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);
 }
コード例 #4
0
ファイル: Extensions.cs プロジェクト: caprapaul/assignments
 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];
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: Encoder.cs プロジェクト: caprapaul/assignments
        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);
        }
    }
}