Пример #1
0
		/// <summary>
		/// Reduce noise using conservative smoothing.
		/// </summary>
		/// <param name="bitmap">The bitmap.</param>
		public static Bitmap Noise(this Bitmap bitmap) {
			if ((bitmap = bitmap.Channel()) != null) {
				var conservativeSmoothing = new ConservativeSmoothing();
				conservativeSmoothing.ApplyInPlace(bitmap);
			}
			return bitmap;
		}
Пример #2
0
        private void button18_Click(object sender, EventArgs e) /// Extract Watermark At Once
        {
            if(dwtTypeValue2.Text == "Haar")
            {
                GUIStart("Extracting Watermark...");

                #region Training HMM and Detection
                /// Detection            
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Select a key accordingly";
                ofd.InitialDirectory = @"F:\College\Semester 8\TA2\TugasAkhir1\TugasAkhir1\Key";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    StreamReader objstream = new StreamReader(ofd.FileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int hostheight = Convert.ToInt32(lines[1]);
                    int hostwidth = Convert.ToInt32(lines[2]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    KeyFileName = ofd.FileName;

                    /// Get PNSeq
                    List<int> PNSeq = new List<int>();
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    //GUIStart("Training HMM Model...");
                    //transformedImage.Image = DWT.TransformDWT(true, false, 2, OriginalImage);

                    ///For Wavelet Coefficients Extraction
                    Bitmap b = new Bitmap(transformedImage.Image);
                    IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1;
                    IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2;
                    IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3;

                    double[,] ArrayImage = IMatrixG; //Embedding in Green 
                                                     //Watermarked_Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, 2);
                    RedWatermarked_Wavelet_Coefficients = Haar.WaveletCoeff(IMatrixR, true, 2);
                    GreenWatermarked_Wavelet_Coefficients = Haar.WaveletCoeff(IMatrixG, true, 2);
                    BlueWatermarked_Wavelet_Coefficients = Haar.WaveletCoeff(IMatrixB, true, 2);

                    int NumOfScale2 = ((hostheight * hostwidth) / 16) * 3;


                    Image decomposed = Haar.TransformDWT(true, false, 2, new Bitmap(transformedImage.Image)).Item4;
                    //RedExtractedWatermark = Extract.BaumWelchDetectionRGB(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq , "red"/*, rootpmf, transition, variances*/);
                    //GreenExtractedWatermark = Extract.BaumWelchDetectionRGB(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green" /*, rootpmf, transition, variances*/);
                    //BlueExtractedWatermark = Extract.BaumWelchDetectionRGB(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "blue" /*, rootpmf, transition, variances*/);
                    string subband = subbandValue2.Text;
                    double embed_constant = Convert.ToDouble(embedConstantValue2.Text);
                    if (HVSValue.Text == "Xie Model")
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_2(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_2(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_2(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }
                    else
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_22(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_22(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_22(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }

                }
                else
                {
                    MessageBox.Show("Select Key accordingly first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                #region Extraction
                if (KeyFileName != null)
                {
                    GUIStart("Extracting Watermark...");

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

                    StreamReader objstream = new StreamReader(KeyFileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int height = Convert.ToInt32(lines[4]);
                    int width = Convert.ToInt32(lines[5]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    #region Extracting Image in Red
                    /////Not using 15 bit mapping
                    //Bitmap redbmp = ImageProcessing.ConvertListToWatermark2(RedExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter = new ConservativeSmoothing();
                    //filter.ApplyInPlace(redbmp);
                    //extractedImageRed.Image = redbmp;
                    #endregion

                    #region Extraction Image in Green
                    /////Not using 15 bit mapping
                    //Bitmap greenbmp = ImageProcessing.ConvertListToWatermark2(GreenExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter2 = new ConservativeSmoothing();
                    //filter2.ApplyInPlace(greenbmp);
                    //extractedImageGreen.Image = greenbmp;
                    #endregion

                    #region Extraction Image in Blue
                    /////Not using 15 bit mapping
                    //Bitmap bluebmp = ImageProcessing.ConvertListToWatermark2(BlueExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter3 = new ConservativeSmoothing();
                    //filter3.ApplyInPlace(greenbmp);
                    //extractedImageBlue.Image = bluebmp;
                    #endregion

                    #region Get Final Result
                    double[] finalresult = Extract.FinalResult(RedExtractedWatermark, GreenExtractedWatermark, BlueExtractedWatermark);
                    Bitmap finalbmp = ImageProcessing.ConvertListToWatermark2(finalresult, height, width);
                    ConservativeSmoothing filter4 = new ConservativeSmoothing();
                    filter4.ApplyInPlace(finalbmp);
                    FinalResult.Image = finalbmp;
                    #endregion

                    FResult = finalresult;

                    if (watermarkImage.Image != null && Real_Watermark!=null)
                    {
                        #region Red BER Calculation
                        /// Test
                        int counter = 0;
                        for (int i = 0; i < RedExtractedWatermark.Length; i++)
                        {
                            if (RedExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter++;
                            }
                        }
                        double akurasi = ((double)counter / (double)RedExtractedWatermark.Length) * 100;
                        double BER = 100 - akurasi;
                        //bertxt.Text += "> " + Math.Round(BER, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //RedextractedBERtxt.Text = Math.Round(BER, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Green BER Calculation
                        /// Test
                        int counter2 = 0;
                        for (int i = 0; i < GreenExtractedWatermark.Length; i++)
                        {
                            if (GreenExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter2++;
                            }
                        }
                        double akurasi2 = ((double)counter2 / (double)GreenExtractedWatermark.Length) * 100;
                        double BER2 = 100 - akurasi2;
                        //bertxt.Text += "> " + Math.Round(BER2, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //GreenextractedBERtxt.Text = Math.Round(BER2, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Blue BER Calculation
                        /// Test
                        int counter3 = 0;
                        for (int i = 0; i < BlueExtractedWatermark.Length; i++)
                        {
                            if (BlueExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter3++;
                            }
                        }
                        double akurasi3 = ((double)counter3 / (double)BlueExtractedWatermark.Length) * 100;
                        double BER3 = 100 - akurasi3;
                        //bertxt.Text += "> " + Math.Round(BER3, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //BlueextractedBERtxt.Text = Math.Round(BER3, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Final BER Calculation
                        /// Test
                        int counter4 = 0;
                        for (int i = 0; i < finalresult.Length; i++)
                        {
                            if (finalresult[i] == Real_Watermark[i])
                            {
                                counter4++;
                            }
                        }
                        double akurasi4 = ((double)counter4 / (double)finalresult.Length) * 100;
                        double BER4 = 100 - akurasi4;
                        bertxt.Text += "> " + Math.Round(BER4, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        finalBerValue.Text = Math.Round(BER4, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion
                    }

                    GUIEnd("Watermark Extracted!", 0, 0, 0);
                }
                else
                {
                    MessageBox.Show("Train and Detect Watermark first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                GUIEnd("Watermark Extracted!", 0, 0, 0);
            }
            else if(dwtTypeValue2.Text == "Db2")
            {
                GUIStart("Extracting Watermark...");

                #region Training HMM and Detection
                /// Detection            
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Select a key accordingly";
                ofd.InitialDirectory = @"F:\College\Semester 8\TA2\TugasAkhir1\TugasAkhir1\Key";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    StreamReader objstream = new StreamReader(ofd.FileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int hostheight = Convert.ToInt32(lines[1]);
                    int hostwidth = Convert.ToInt32(lines[2]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    KeyFileName = ofd.FileName;

                    /// Get PNSeq
                    List<int> PNSeq = new List<int>();
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    GUIStart("Training HMM Model...");
                    //transformedImage.Image = DWT.TransformDWT(true, false, 2, OriginalImage);

                    ///For Wavelet Coefficients Extraction
                    Bitmap b = new Bitmap(transformedImage.Image);
                    IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1;
                    IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2;
                    IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3;

                    double[,] ArrayImage = IMatrixG; //Embedding in Green 
                                                     //Watermarked_Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, 2);
                    RedWatermarked_Wavelet_Coefficients = Daubechies2.WaveletCoeff(IMatrixR, true, 2);
                    GreenWatermarked_Wavelet_Coefficients = Daubechies2.WaveletCoeff(IMatrixG, true, 2);
                    BlueWatermarked_Wavelet_Coefficients = Daubechies2.WaveletCoeff(IMatrixB, true, 2);

                    int NumOfScale2 = ((hostheight * hostwidth) / 16) * 3;


                    Image decomposed = Haar.TransformDWT(true, false, 2, new Bitmap(transformedImage.Image)).Item4;
                    //RedExtractedWatermark = Extract.BaumWelchDetectionRGB(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq , "red"/*, rootpmf, transition, variances*/);
                    //GreenExtractedWatermark = Extract.BaumWelchDetectionRGB(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green" /*, rootpmf, transition, variances*/);
                    //BlueExtractedWatermark = Extract.BaumWelchDetectionRGB(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "blue" /*, rootpmf, transition, variances*/);
                    string subband = subbandValue2.Text;
                    double embed_constant = Convert.ToDouble(embedConstantValue2.Text);
                    if (HVSValue.Text == "Xie Model")
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_2(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_2(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_2(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }
                    else
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_22(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_22(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_22(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }

                }
                else
                {
                    MessageBox.Show("Select Key accordingly first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                #region Extraction
                if (KeyFileName != null)
                {
                    GUIStart("Extracting Watermark...");

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

                    StreamReader objstream = new StreamReader(KeyFileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int height = Convert.ToInt32(lines[4]);
                    int width = Convert.ToInt32(lines[5]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    #region Extracting Image in Red
                    /////Not using 15 bit mapping
                    //Bitmap redbmp = ImageProcessing.ConvertListToWatermark2(RedExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter = new ConservativeSmoothing();
                    //filter.ApplyInPlace(redbmp);
                    //extractedImageRed.Image = redbmp;
                    #endregion

                    #region Extraction Image in Green
                    /////Not using 15 bit mapping
                    //Bitmap greenbmp = ImageProcessing.ConvertListToWatermark2(GreenExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter2 = new ConservativeSmoothing();
                    //filter2.ApplyInPlace(greenbmp);
                    //extractedImageGreen.Image = greenbmp;
                    #endregion

                    #region Extraction Image in Blue
                    /////Not using 15 bit mapping
                    //Bitmap bluebmp = ImageProcessing.ConvertListToWatermark2(BlueExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter3 = new ConservativeSmoothing();
                    //filter3.ApplyInPlace(greenbmp);
                    //extractedImageBlue.Image = bluebmp;
                    #endregion

                    #region Get Final Result
                    double[] finalresult = Extract.FinalResult(RedExtractedWatermark, GreenExtractedWatermark, BlueExtractedWatermark);
                    Bitmap finalbmp = ImageProcessing.ConvertListToWatermark2(finalresult, height, width);
                    ConservativeSmoothing filter4 = new ConservativeSmoothing();
                    filter4.ApplyInPlace(finalbmp);
                    FinalResult.Image = finalbmp;
                    #endregion

                    FResult = finalresult;

                    if (watermarkImage.Image != null && Real_Watermark != null)
                    {
                        #region Red BER Calculation
                        /// Test
                        int counter = 0;
                        for (int i = 0; i < RedExtractedWatermark.Length; i++)
                        {
                            if (RedExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter++;
                            }
                        }
                        double akurasi = ((double)counter / (double)RedExtractedWatermark.Length) * 100;
                        double BER = 100 - akurasi;
                        //bertxt.Text += "> " + Math.Round(BER, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //RedextractedBERtxt.Text = Math.Round(BER, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Green BER Calculation
                        /// Test
                        int counter2 = 0;
                        for (int i = 0; i < GreenExtractedWatermark.Length; i++)
                        {
                            if (GreenExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter2++;
                            }
                        }
                        double akurasi2 = ((double)counter2 / (double)GreenExtractedWatermark.Length) * 100;
                        double BER2 = 100 - akurasi2;
                        //bertxt.Text += "> " + Math.Round(BER2, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //GreenextractedBERtxt.Text = Math.Round(BER2, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Blue BER Calculation
                        /// Test
                        int counter3 = 0;
                        for (int i = 0; i < BlueExtractedWatermark.Length; i++)
                        {
                            if (BlueExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter3++;
                            }
                        }
                        double akurasi3 = ((double)counter3 / (double)BlueExtractedWatermark.Length) * 100;
                        double BER3 = 100 - akurasi3;
                        //bertxt.Text += "> " + Math.Round(BER3, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //BlueextractedBERtxt.Text = Math.Round(BER3, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Final BER Calculation
                        /// Test
                        int counter4 = 0;
                        for (int i = 0; i < finalresult.Length; i++)
                        {
                            if (finalresult[i] == Real_Watermark[i])
                            {
                                counter4++;
                            }
                        }
                        double akurasi4 = ((double)counter4 / (double)finalresult.Length) * 100;
                        double BER4 = 100 - akurasi4;
                        bertxt.Text += "> " + Math.Round(BER4, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        finalBerValue.Text = Math.Round(BER4, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion
                    }

                    GUIEnd("Watermark Extracted!", 0, 0, 0);
                }
                else
                {
                    MessageBox.Show("Train and Detect Watermark first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                GUIEnd("Watermark Extracted!", 0, 0, 0);
            }
            else
            {
                GUIStart("Extracting Watermark...");

                #region Training HMM and Detection
                /// Detection            
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Select a key accordingly";
                ofd.InitialDirectory = @"F:\College\Semester 8\TA2\TugasAkhir1\TugasAkhir1\Key";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    StreamReader objstream = new StreamReader(ofd.FileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int hostheight = Convert.ToInt32(lines[1]);
                    int hostwidth = Convert.ToInt32(lines[2]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    KeyFileName = ofd.FileName;

                    /// Get PNSeq
                    List<int> PNSeq = new List<int>();
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    GUIStart("Training HMM Model...");
                    //transformedImage.Image = DWT.TransformDWT(true, false, 2, OriginalImage);

                    ///For Wavelet Coefficients Extraction
                    Bitmap b = new Bitmap(transformedImage.Image);
                    IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1;
                    IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2;
                    IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3;

                    double[,] ArrayImage = IMatrixG; //Embedding in Green 
                                                     //Watermarked_Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, 2);
                    RedWatermarked_Wavelet_Coefficients = Daubechies3.WaveletCoeff(IMatrixR, true, 2);
                    GreenWatermarked_Wavelet_Coefficients = Daubechies3.WaveletCoeff(IMatrixG, true, 2);
                    BlueWatermarked_Wavelet_Coefficients = Daubechies3.WaveletCoeff(IMatrixB, true, 2);

                    int NumOfScale2 = ((hostheight * hostwidth) / 16) * 3;


                    Image decomposed = Haar.TransformDWT(true, false, 2, new Bitmap(transformedImage.Image)).Item4;
                    //RedExtractedWatermark = Extract.BaumWelchDetectionRGB(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq , "red"/*, rootpmf, transition, variances*/);
                    //GreenExtractedWatermark = Extract.BaumWelchDetectionRGB(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green" /*, rootpmf, transition, variances*/);
                    //BlueExtractedWatermark = Extract.BaumWelchDetectionRGB(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "blue" /*, rootpmf, transition, variances*/);
                    string subband = subbandValue2.Text;
                    double embed_constant = Convert.ToDouble(embedConstantValue2.Text);
                    if (HVSValue.Text == "Xie Model")
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_2(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_2(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_2(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }
                    else
                    {
                        RedExtractedWatermark = Extract.BaumWelchDetectionInLH_22(RedWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Red", subband, embed_constant);
                        GreenExtractedWatermark = Extract.BaumWelchDetectionInLH_22(GreenWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "green", subband, embed_constant);
                        BlueExtractedWatermark = Extract.BaumWelchDetectionInLH_22(BlueWatermarked_Wavelet_Coefficients, decomposed, NumOfScale2, NumOfTrees, PNSeq, "Blue", subband, embed_constant);
                    }

                }
                else
                {
                    MessageBox.Show("Select Key accordingly first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                #region Extraction
                if (KeyFileName != null)
                {
                    GUIStart("Extracting Watermark...");

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

                    StreamReader objstream = new StreamReader(KeyFileName);
                    string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                    int height = Convert.ToInt32(lines[4]);
                    int width = Convert.ToInt32(lines[5]);
                    int NumOfTrees = Convert.ToInt32(lines[7]);
                    for (int i = 9; i < lines.Length - 1; i++)
                    {
                        PNSeq.Add(Convert.ToInt32(lines[i]));
                    }

                    #region Extracting Image in Red
                    /////Not using 15 bit mapping
                    //Bitmap redbmp = ImageProcessing.ConvertListToWatermark2(RedExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter = new ConservativeSmoothing();
                    //filter.ApplyInPlace(redbmp);
                    //extractedImageRed.Image = redbmp;
                    #endregion

                    #region Extraction Image in Green
                    /////Not using 15 bit mapping
                    //Bitmap greenbmp = ImageProcessing.ConvertListToWatermark2(GreenExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter2 = new ConservativeSmoothing();
                    //filter2.ApplyInPlace(greenbmp);
                    //extractedImageGreen.Image = greenbmp;
                    #endregion

                    #region Extraction Image in Blue
                    /////Not using 15 bit mapping
                    //Bitmap bluebmp = ImageProcessing.ConvertListToWatermark2(BlueExtractedWatermark, height, width);
                    ////watermarkImage.Image = bmp;
                    ////Bitmap bmp = new Bitmap(watermarkImage.Image);               
                    //ConservativeSmoothing filter3 = new ConservativeSmoothing();
                    //filter3.ApplyInPlace(greenbmp);
                    //extractedImageBlue.Image = bluebmp;
                    #endregion

                    #region Get Final Result
                    double[] finalresult = Extract.FinalResult(RedExtractedWatermark, GreenExtractedWatermark, BlueExtractedWatermark);
                    Bitmap finalbmp = ImageProcessing.ConvertListToWatermark2(finalresult, height, width);
                    ConservativeSmoothing filter4 = new ConservativeSmoothing();
                    filter4.ApplyInPlace(finalbmp);
                    FinalResult.Image = finalbmp;
                    #endregion

                    FResult = finalresult;

                    if (watermarkImage.Image != null && Real_Watermark != null)
                    {
                        #region Red BER Calculation
                        /// Test
                        int counter = 0;
                        for (int i = 0; i < RedExtractedWatermark.Length; i++)
                        {
                            if (RedExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter++;
                            }
                        }
                        double akurasi = ((double)counter / (double)RedExtractedWatermark.Length) * 100;
                        double BER = 100 - akurasi;
                        //bertxt.Text += "> " + Math.Round(BER, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //RedextractedBERtxt.Text = Math.Round(BER, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Green BER Calculation
                        /// Test
                        int counter2 = 0;
                        for (int i = 0; i < GreenExtractedWatermark.Length; i++)
                        {
                            if (GreenExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter2++;
                            }
                        }
                        double akurasi2 = ((double)counter2 / (double)GreenExtractedWatermark.Length) * 100;
                        double BER2 = 100 - akurasi2;
                        //bertxt.Text += "> " + Math.Round(BER2, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //GreenextractedBERtxt.Text = Math.Round(BER2, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion

                        #region Blue BER Calculation
                        /// Test
                        int counter3 = 0;
                        for (int i = 0; i < BlueExtractedWatermark.Length; i++)
                        {
                            if (BlueExtractedWatermark[i] == Real_Watermark[i])
                            {
                                counter3++;
                            }
                        }
                        double akurasi3 = ((double)counter3 / (double)BlueExtractedWatermark.Length) * 100;
                        double BER3 = 100 - akurasi3;
                        //bertxt.Text += "> " + Math.Round(BER3, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        //BlueextractedBERtxt.Text = Math.Round(BER3, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion


                        #region Final BER Calculation
                        /// Test
                        int counter4 = 0;
                        for (int i = 0; i < finalresult.Length; i++)
                        {
                            if (finalresult[i] == Real_Watermark[i])
                            {
                                counter4++;
                            }
                        }
                        double akurasi4 = ((double)counter4 / (double)finalresult.Length) * 100;
                        double BER4 = 100 - akurasi4;
                        bertxt.Text += "> " + Math.Round(BER4, 2) + " %" + "\n";
                        //double BER = Statistic.BER(new Bitmap(watermarkImage.Image), new Bitmap(extractedImageGreen.Image));
                        finalBerValue.Text = Math.Round(BER4, 2).ToString();
                        //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);
                        #endregion
                    }

                    GUIEnd("Watermark Extracted!", 0, 0, 0);
                }
                else
                {
                    MessageBox.Show("Train and Detect Watermark first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
                }
                #endregion

                GUIEnd("Watermark Extracted!", 0, 0, 0);
            }
            
        }
Пример #3
0
        private void button17_Click(object sender, EventArgs e)
        {
            if (KeyFileName != null)
            {
                GUIStart("Extracting Watermark...");

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

                StreamReader objstream = new StreamReader(KeyFileName);
                string[] lines = objstream.ReadToEnd().Split(new char[] { '\n' });
                int height = Convert.ToInt32(lines[4]);
                int width = Convert.ToInt32(lines[5]);
                int NumOfTrees = Convert.ToInt32(lines[7]);
                for (int i = 9; i < lines.Length - 1; i++)
                {
                    PNSeq.Add(Convert.ToInt32(lines[i]));
                }

                #region Extracting Image
                ///Not using 15 bit mapping
                Bitmap bmp = ImageProcessing.ConvertListToWatermark2(ExtractedWatermark, height, width);
                //watermarkImage.Image = bmp;
                //Bitmap bmp = new Bitmap(watermarkImage.Image);               
                ConservativeSmoothing filter = new ConservativeSmoothing();
                filter.ApplyInPlace(bmp);
                //extractedImageRed.Image = bmp;
                #endregion

                /// Test
                int counter = 0;
                for (int i = 0; i < ExtractedWatermark.Length; i++)
                {
                    if(ExtractedWatermark[i] == Real_Watermark[i])
                    {
                        counter++;
                    }
                }
                double akurasi = ((double)counter/(double)ExtractedWatermark.Length)*100;
                double BER = 100 - akurasi;
                bertxt.Text += Math.Round(BER,2)+"\n";
                //MessageBox.Show("Akurasi: " + BER, "Succeed!", MessageBoxButtons.OK);

                GUIEnd("Watermark Extracted!", 0, 0, 0);
            }
            else
            {
                MessageBox.Show("Train and Detect Watermark first!", "Incomplete Procedure Detected", MessageBoxButtons.OK);
            }                
        }
Пример #4
0
 /// <summary>
 /// Reduce noise using conservative smoothing.
 /// </summary>
 public static Bitmap Noise(this Bitmap Bitmap)
 {
     // Convert grayscale to RGB colour space.
     if ((Bitmap = Bitmap.Channel()) != null) {
         // Initialize a new instance of the ConservativeSmoothing class.
         var ConservativeSmoothing = new ConservativeSmoothing();
         // Reduce noise while preserving detail.
         ConservativeSmoothing.ApplyInPlace(Bitmap);
     }
     // Return the bitmap.
     return Bitmap;
 }