示例#1
0
        private static Vector <Matrix>[,] SplitToBlocksInt(Vector <int>[,] map, int blockSize)
        {
            var result = new Vector <Matrix> [map.GetLength(0) / blockSize, map.GetLength(1) / blockSize];

            for (var i = 0; i < map.GetLength(0); i += blockSize)
            {
                for (var j = 0; j < map.GetLength(1); j += blockSize)
                {
                    var array = new Vector <double> [blockSize, blockSize];
                    for (var x = 0; x < blockSize; ++x)
                    {
                        for (var y = 0; y < blockSize; ++y)
                        {
                            array[x, y] = map[i + x, j + y].Convert(Convert.ToDouble);
                        }
                    }
                    var matrices = new Matrix[3];
                    for (var k = 0; k < 3; ++k)
                    {
                        matrices[k] = new Matrix(Project(array, k));
                    }
                    result[i / blockSize, j / blockSize] = new Vector <Matrix>(matrices);
                }
            }
            return(result);
        }
示例#2
0
        private static Matrix GetQuantizationMatrix(MatrixGenerators generators)
        {
            var result = new Matrix(8, 8);

            for (var i = 0; i < 8; ++i)
            {
                for (var j = 0; j < 8; ++j)
                {
                    result[i, j] = generators.Alpha * (1 + generators.Gamma * (i + j + 2));
                }
            }
            return(result);
        }
示例#3
0
        private static Matrix GetDctMatrix()
        {
            var result = new Matrix(8, 8);

            for (var j = 0; j < 8; ++j)
            {
                result[0, j] = 1.0 / Math.Sqrt(8);
            }
            for (var i = 1; i < 8; ++i)
            {
                for (var j = 0; j < 8; ++j)
                {
                    result[i, j] = 0.5 * Math.Cos((2 * j + 1) * i * Math.PI / 16.0);
                }
            }
            return(result);
        }
示例#4
0
        private static Vector <Matrix>[,] ApplyDct(Vector <Matrix>[,] blocks, Matrix dct, Matrix transposedDct)
        {
            var n      = blocks.GetLength(0);
            var m      = blocks.GetLength(1);
            var result = new Vector <Matrix> [n, m];

            for (var i = 0; i < n; ++i)
            {
                for (var j = 0; j < m; ++j)
                {
                    result[i, j] = new Vector <Matrix>(3);
                    for (var k = 0; k < 3; ++k)
                    {
                        result[i, j][k] = dct * blocks[i, j][k] * transposedDct;
                    }
                }
            }
            return(result);
        }
示例#5
0
 private static Vector <Matrix>[,] DequantizeByMatrices(Vector <Matrix>[,] appliedDct, Matrix matrixY, Matrix matrixC)
 {
     for (var i = 0; i < appliedDct.GetLength(0); ++i)
     {
         for (var j = 0; j < appliedDct.GetLength(1); ++j)
         {
             appliedDct[i, j][0] = appliedDct[i, j][0] % matrixY;
             appliedDct[i, j][1] = appliedDct[i, j][1] % matrixC;
             appliedDct[i, j][2] = appliedDct[i, j][2] % matrixC;
         }
     }
     return(appliedDct);
 }