} //**************************** end Encode ************************************************

        private void button6_Click(object sender, EventArgs e) // Restore
        {
            if (!OPEN)
            {
                MessageBox.Show("Please open an image");
                return;
            }

            if (!IMPULSE)
            {
                MessageBox.Show("Please click 'Impulse noise'");
                return;
            }

            if (!SEGMENTED)
            {
                MessageBox.Show("Please click 'Segment'");
                return;
            }

            if (!DETECTED)
            {
                MessageBox.Show("Please click 'Detect edges'");
                return;
            }

            if (!CODED)
            {
                MessageBox.Show("Please click 'Encode'");
                return;
            }

            CImage MaskIm = new CImage(origBmp.Width, origBmp.Height, 8);

            RestoreIm = new CImage(origBmp.Width, origBmp.Height, 24);
            LiCod.Restore(ref RestoreIm, ref MaskIm, this);

            RestoreIm.Smooth(ref MaskIm, false, this);

            ImageToBitmapNew(RestoreIm, BmpPictBox2); // RestoreIm is always color image but BmpPictBox2 can be indexed
            pictureBox2.Image = BmpPictBox2;

            pictureBox2.Image = BmpPictBox2;
            pictureBox2.Refresh();
            progressBar1.Visible = false;
            label3.Text          = "Restored image";
            label3.Visible       = true;
            label7.Text          = "Click 'Save code \\DAT'";
            label7.Visible       = true;
            button7.Visible      = true;
        } //********************************* end Restore *****************************