Пример #1
0
        private void EncodeBttn_Click(object sender, EventArgs e)
        {
            _imgPred = new ImagePredictor(k: int.Parse(textBoxKVal.Text));
            _imgPred.Encode(_originalImg, methodNumber: methodComboBox.SelectedIndex);

            _errorPredSaved = _imgPred._errorPred;
            _mainError      = _imgPred._error;
            _quantizedError = _imgPred._errorPredQ;
        }
Пример #2
0
        private void DecodeBttn_Click(object sender, EventArgs e)
        {
            bread     = new BitReader(filePath.FullName);
            bmpHeader = readBMPHeader();
            int fileMethod = (int)bread.ReadNBits(4);
            var errorList  = readErrorMatrix();

            bread.Dispose();

            int[,] errorMatrix = new int[imgLength, imgLength];
            int k = 0;

            for (int i = 0; i < imgLength; i++)
            {
                for (int j = 0; j < imgLength; j++)
                {
                    errorMatrix[i, j] = (int)errorList[k];
                    k++;
                }
            }

            imgPred = new ImagePredictor();
            imgPred.Decode(errorMatrix, methodName: fileMethod);
            decodedImg = imgPred.origDecodedMatrix;

            DecodedPBox.Image = new Bitmap(imgLength, imgLength);
            for (int i = 0; i < imgLength; i++)
            {
                for (int j = 0; j < imgLength; j++)
                {
                    int color = decodedImg[i, j];
                    ((Bitmap)DecodedPBox.Image).SetPixel(i, j, Color.FromArgb(color, color, color));
                }
            }
            //DecodedPBox.Image.Save(filePath.DirectoryName + "\\decodedImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        }
Пример #3
0
 private void EncodeBttn_Click(object sender, EventArgs e)
 {
     imgPred = new ImagePredictor();
     imgPred.Encode(originalImg, methodNumber: methodComboBox.SelectedIndex);
 }
Пример #4
0
        private void DecodeBttn_Click(object sender, EventArgs e)
        {
            _bitReader = new BitReader(_filePath.FullName);
            _bmpHeader = readBMPHeader();
            int fileMethod = (int)_bitReader.ReadNBits(4);
            int k          = (int)_bitReader.ReadNBits(4);
            int saveMode   = (int)_bitReader.ReadNBits(2);

            List <int> errorList = new List <int>();

            switch (saveMode)
            {
            case 0:
                errorList = new List <int>(readFixedCompressedFile());
                break;

            case 1:
                errorList = new List <int>(readJpegTableCompressedFile());
                break;

            case 2:
                errorList = new List <int>(readArithmeticCompressedFile());
                break;
            }

            _bitReader.Dispose();

            if (!errorList.Any())
            {
                throw new Exception("Something didn't work correctly at decoding!");
            }

            int[,] errorPredQ = new int[_imgLength, _imgLength];

            // from List to matrix conversion
            int index = 0;

            for (int i = 0; i < _imgLength; i++)
            {
                for (int j = 0; j < _imgLength; j++)
                {
                    errorPredQ[i, j] = errorList[index];
                    index++;
                }
            }

            _imgPred = new ImagePredictor(k: k);
            _imgPred.Decode(errorPredQ, methodNumber: fileMethod);
            _decodedImg = _imgPred._decod;

            DecodedPBox.Image = new Bitmap(_imgLength, _imgLength);
            for (int i = 0; i < _imgLength; i++)
            {
                for (int j = 0; j < _imgLength; j++)
                {
                    int color = _decodedImg[i, j];
                    ((Bitmap)DecodedPBox.Image).SetPixel(i, j, Color.FromArgb(color, color, color));
                }
            }
            //DecodedPBox.Image.Save(filePath.DirectoryName + "\\decodedImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        }