示例#1
0
        YCrCb rgbToYCbCr(Bitmap img)
        {
            YCrCb result;
            Color color;

            byte[,] y  = new byte[img.Width, img.Height];
            byte[,] cb = new byte[img.Width, img.Height];
            byte[,] cr = new byte[img.Width, img.Height];
            int R = 0;
            int G = 0;
            int B = 0;

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    color    = image.GetPixel(i, j);
                    R        = color.R;
                    G        = color.G;
                    B        = color.B;
                    y[i, j]  = (byte)(0 + 0.299 * R + 0.587 * G + 0.114 * B);
                    cb[i, j] = (byte)(128 - 0.168736 * R - 0.331264 * G + 0.5 * B);
                    cr[i, j] = (byte)(128 + 0.5 * R - 0.418688 * G - 0.081312 * B);
                }
            }
            result = new YCrCb(y, cb, cr);
            return(result);
        }
示例#2
0
        private void dCTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            double[,] yDCT, CbDCT, CrDCT, yInvQed, CbInvQed, CrInvQed;
            byte[,] yQuantized, CbQuantized, CrQuantized, yInvDCT, CbInvDCT, CrInvDCT;
            Bitmap result, subsamplebmp;
            YCrCb  subsampled, desubsampled;

            rgbConverted = rgbToYCbCr(image);
            subsampled   = compress(rgbConverted.Y, rgbConverted.Cb, rgbConverted.Cr);
            //subsamplebmp = YCbCrTorgb(subsampled.Y, subsampled.Cb, subsampled.Cr);
            //decompressed = decompress(compressed.Y, compressed.Cb, compressed.Cr);
            //bmpDecompressed = YCbCrTorgb(decompressed.Y, decompressed.Cb, decompressed.Cr);

            yDCT  = dctObject.forwardDCT(subsampled.Y);
            CbDCT = dctObject.forwardDCT(subsampled.Cb);
            CrDCT = dctObject.forwardDCT(subsampled.Cr);

            yQuantized  = dctObject.quantize(yDCT);
            CbQuantized = dctObject.quantize(CbDCT);
            CrQuantized = dctObject.quantize(CrDCT);

            yInvQed  = dctObject.inverseQuantize(yQuantized);
            CbInvQed = dctObject.inverseQuantize(CbQuantized);
            CrInvQed = dctObject.inverseQuantize(CrQuantized);

            yInvDCT  = dctObject.inverseDCT(yInvQed);
            CbInvDCT = dctObject.inverseDCT(CbInvQed);
            CrInvDCT = dctObject.inverseDCT(CrInvQed);

            desubsampled = decompress(yInvDCT, CbInvDCT, CrInvDCT);
            result       = YCbCrTorgb(desubsampled.Y, desubsampled.Cb, desubsampled.Cr);

            pictureBox2.Image = result;
        }
示例#3
0
 private void compressionToolStripMenuItem_Click(object sender, EventArgs e)
 {
     rgbConverted      = rgbToYCbCr(image);
     compressed        = compress(rgbConverted.Y, rgbConverted.Cb, rgbConverted.Cr);
     decompressed      = decompress(compressed.Y, compressed.Cb, compressed.Cr);
     bmpDecompressed   = YCbCrTorgb(decompressed.Y, decompressed.Cb, decompressed.Cr);
     pictureBox2.Image = bmpDecompressed;
 }