public static CompressedImage CompressWithDCT(this double[,] channelPixels, int DCTSize, int compressionLevel = 4)
        {
            var frequencesPerBlock = -1;

            var height = channelPixels.GetLength(0);
            var width  = channelPixels.GetLength(1);

            var result = new List <double>();

            for (var y = 0; y < height; y += DCTSize)
            {
                for (var x = 0; x < width; x += DCTSize)
                {
                    var subMatrix = channelPixels.GetSubMatrix(y, DCTSize, x, DCTSize, DCTSize);
                    subMatrix.ShiftMatrixValues(-128);

                    var channelFreqs = DCTTransformer.DCT2D(subMatrix);

                    frequencesPerBlock = DCTSize * DCTSize;
                    for (var i = 0; i < DCTSize; i++)
                    {
                        for (var j = 0; j < DCTSize; j++)
                        {
                            if (i + j < compressionLevel)
                            {
                                result.Add(channelFreqs[i, j]);
                                continue;
                            }
                            channelFreqs[i, j] = 0;
                            frequencesPerBlock--;
                        }
                    }
                }
            }

            return(new CompressedImage {
                CompressionLevel = compressionLevel, FrequencesPerBlock = frequencesPerBlock, Frequences = result, Height = height, Width = width
            });
        }
        private static List <double> GetFrequencesFromSubmatrix(double[,] channelPixels,
                                                                int DCTSize, int compressionLevel, int y, int x)
        {
            var subMatrix = channelPixels.GetSubMatrix(y, DCTSize, x, DCTSize, DCTSize);

            subMatrix.ShiftMatrixValues(-128);
            var localResult  = new List <double>();
            var channelFreqs = DCTTransformer.DCT2D(subMatrix);

            for (var i = 0; i < DCTSize; i++)
            {
                for (var j = 0; j < DCTSize; j++)
                {
                    if (i + j < compressionLevel)
                    {
                        localResult.Add(channelFreqs[i, j]);
                        continue;
                    }
                    channelFreqs[i, j] = 0;
                }
            }
            return(localResult);
        }