private void button8_Click(object sender, EventArgs e) /// Do Embedding Process at once { #region FDWT if (dwtTypeValue.Text == "Haar") { if (hostImage.Image != null) { GUIStart("Processing...!"); //int level = Convert.ToInt32(HVSValue.Text); ///For Visualization OriginalImage = new Bitmap(hostImage.Image); transformedImage.Image = Haar.TransformDWT(true, false, 2, OriginalImage).Item4; ///For Wavelet Coefficients Extraction Bitmap b = new Bitmap(hostImage.Image); IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1; IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2; IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3; //double[,] IMatrix = ImageProcessing.ConvertToMatrix(b); //Test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); double[,] ArrayImage = IMatrixG; //Embedding in Green //Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, level); Red_Coeffs = Haar.WaveletCoeff(IMatrixR, true, 2); Green_Coeffs = Haar.WaveletCoeff(IMatrixG, true, 2); Blue_Coeffs = Haar.WaveletCoeff(IMatrixB, true, 2); resultLbl.Text = "Decomposed Host Image"; GUIEnd("FDWT Succeed!", 0, 0, 0); /// Test //int c = 1; //TextWriter tw2 = new StreamWriter("GreenPixels.txt"); //tw2.WriteLine("Total Watermark "); //for (int i = 0; i < IMatrixG.GetLength(0); i++) //{ // for (int j = 0; j < IMatrixG.GetLength(1); j++) // { // tw2.Write("[" + c + "]" + IMatrixG[i, j] + " - "); // c++; // } // tw2.WriteLine(); //} //tw2.Close(); } else { MessageBox.Show("Load Image First", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } } else if (dwtTypeValue.Text == "Db2") { if (hostImage.Image != null) { GUIStart("Processing...!"); //int level = Convert.ToInt32(HVSValue.Text); ///For Visualization OriginalImage = new Bitmap(hostImage.Image); transformedImage.Image = Daubechies2.TransformDWT(true, false, 2, OriginalImage).Item4; ///For Wavelet Coefficients Extraction Bitmap b = new Bitmap(hostImage.Image); IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1; IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2; IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3; //double[,] IMatrix = ImageProcessing.ConvertToMatrix(b); //Test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); double[,] ArrayImage = IMatrixG; //Embedding in Green //Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, level); Red_Coeffs = Daubechies2.WaveletCoeff(IMatrixR, true, 2); Green_Coeffs = Daubechies2.WaveletCoeff(IMatrixG, true, 2); Blue_Coeffs = Daubechies2.WaveletCoeff(IMatrixB, true, 2); resultLbl.Text = "Decomposed Host Image"; GUIEnd("FDWT Succeed!", 0, 0, 0); /// Test //int c = 1; //TextWriter tw2 = new StreamWriter("GreenPixels.txt"); //tw2.WriteLine("Total Watermark "); //for (int i = 0; i < IMatrixG.GetLength(0); i++) //{ // for (int j = 0; j < IMatrixG.GetLength(1); j++) // { // tw2.Write("[" + c + "]" + IMatrixG[i, j] + " - "); // c++; // } // tw2.WriteLine(); //} //tw2.Close(); } else { MessageBox.Show("Load Image First", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } } else { if (hostImage.Image != null) { GUIStart("Processing...!"); //int level = Convert.ToInt32(HVSValue.Text); ///For Visualization OriginalImage = new Bitmap(hostImage.Image); transformedImage.Image = Daubechies3.TransformDWT(true, false, 2, OriginalImage).Item4; ///For Wavelet Coefficients Extraction Bitmap b = new Bitmap(hostImage.Image); IMatrixR = ImageProcessing.ConvertToMatrix2(b).Item1; IMatrixG = ImageProcessing.ConvertToMatrix2(b).Item2; IMatrixB = ImageProcessing.ConvertToMatrix2(b).Item3; //double[,] IMatrix = ImageProcessing.ConvertToMatrix(b); //Test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); double[,] ArrayImage = IMatrixG; //Embedding in Green //Wavelet_Coefficients = Haar.WaveletCoeff(ArrayImage, true, level); Red_Coeffs = Daubechies3.WaveletCoeff(IMatrixR, true, 2); Green_Coeffs = Daubechies3.WaveletCoeff(IMatrixG, true, 2); Blue_Coeffs = Daubechies3.WaveletCoeff(IMatrixB, true, 2); resultLbl.Text = "Decomposed Host Image"; GUIEnd("FDWT Succeed!", 0, 0, 0); /// Test //int c = 1; //TextWriter tw2 = new StreamWriter("GreenPixels.txt"); //tw2.WriteLine("Total Watermark "); //for (int i = 0; i < IMatrixG.GetLength(0); i++) //{ // for (int j = 0; j < IMatrixG.GetLength(1); j++) // { // tw2.Write("[" + c + "]" + IMatrixG[i, j] + " - "); // c++; // } // tw2.WriteLine(); //} //tw2.Close(); } else { MessageBox.Show("Load Image First", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } } #endregion #region Scrambling if (watermarkImage.Image == null) { MessageBox.Show("Load Watermark Image First!", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else { if (seedValue.Text.Length > 5 || seedValue.Text == null) { MessageBox.Show("Maximum length of Key is 5 or cannot be empty"); } else { GUIStart("Processing......!"); //double[,] coefficients = coeffs; Bitmap bmp = new Bitmap(watermarkImage.Image); Scramble m = new Scramble(); Bitmap b = ImageProcessing.ConvertToBinary(bmp); List<int> VectorImage = Scramble.ConvertToVectorMatrix(b); //Include integer values between 255 or 0 List<int> BinaryVectorImage = Scramble.ConvertToBinaryVectorMatrix(VectorImage); //Include integer values between 1 or 0 Real_Watermark = BinaryVectorImage; int pnlength = BinaryVectorImage.Count * 5; string pn_seed = seedValue.Text;//"10000"; string pn_mask = "10100"; int pn_length = pnlength; List<int> PNSeq = Scramble.PNSeqLFSR(pn_seed, pn_mask, pn_length); List<int> scrambled_Watermark = Scramble.DSSS(BinaryVectorImage, PNSeq); /// Save into .txt file (PN Sequence and size) Bitmap hostbmp = new Bitmap(hostImage.Image); string hostfilename = HostImageLocationTxt.Text; string watermarkfilename = WatermarkImageLocationTxt.Text; string hostName = Path.GetFileNameWithoutExtension(hostfilename); string watermarkName = Path.GetFileNameWithoutExtension(watermarkfilename); string name = hostName + "_" + watermarkName + "_Key.txt"; int NumOfTrees = pnlength / 5; // Restult in total of tree from segmented watermark , i.e 6480 //TextWriter tw = new StreamWriter(name); using (TextWriter tw = File.CreateText(@"F:\College\Semester 8\TA2\TugasAkhir1\TugasAkhir1\Key\" + name)) { tw.WriteLine("Size of Host Image:"); tw.WriteLine(hostbmp.Height); tw.WriteLine(hostbmp.Width); tw.WriteLine("Size of Watermark: "); tw.WriteLine(bmp.Height); tw.WriteLine(bmp.Width); tw.WriteLine("Number of Trees: "); tw.WriteLine(NumOfTrees); tw.WriteLine("PN Sequence: "); foreach (int i in PNSeq) { tw.WriteLine(i); } tw.Close(); } //List<int> oneminusone = Scramble.ConvertTo1minus1(scrambled_Watermark); Scrambled_Watermark = scrambled_Watermark; //Scrambled_Watermark = oneminusone; GUIEnd("Scramble Succeed!", 0, 0, 0); //MessageBox.Show("Watermark is Succeed. File Was Saved \n Original Watermark: " + BinaryVectorImage.Count + "\n Scrambled Watermark: " + scrambled_Watermark.Count + "\n PN Sequence: " + PNSeq.Count, "Succeed", MessageBoxButtons.OK); //TextWriter tw1 = new StreamWriter("REAL_WATERMARK.txt"); //tw1.WriteLine("Total Real Watermark: " + BinaryVectorImage.Count); //foreach (int i in BinaryVectorImage) // tw1.WriteLine(i); //tw1.Close(); //TextWriter tw2 = new StreamWriter("SCRAMBLED_WATERMARK.txt"); //tw2.WriteLine("Total Scrambled Watermark: " + Scrambled_Watermark.Count); //foreach (int i in Scrambled_Watermark) // tw2.WriteLine(i); //tw2.Close(); //TextWriter tw3 = new StreamWriter("PN_Sequence.txt"); //tw3.WriteLine("Total PN Sequence Watermark: " + PNSeq.Count); //foreach (int i in PNSeq) // tw3.WriteLine(i); //tw3.Close(); } } #endregion #region embed if (hostImage.Image == null) { MessageBox.Show("Load Host Image Image First!", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else if (watermarkImage.Image == null) { MessageBox.Show("Load Watermark Image First!", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else { if (HVSValue.Text == "Xie Model") { #region Xie Model HVS GUIStart("Processing.....!"); List<List<int>> Segmented = Scramble.Segment(Scrambled_Watermark); //double[,] MappedWatermark = Scramble.Mapping(Segmented); // Use mapping into 15 bit each 5 segment of scrambled watermark double[,] MappedWatermark = Scramble.Mapping2(Segmented); // Don't Use mapping Mapped_Watermark = MappedWatermark; #region Red Adaptive HVS double[,] RedHVSValues = new double[Red_Coeffs.GetLength(0), Red_Coeffs.GetLength(1)]; double[,] RedAdaptiveHVS = new double[Red_Coeffs.GetLength(0), Red_Coeffs.GetLength(1)]; double[,] Redpixels = ImageProcessing.ConvertToMatrix2(new Bitmap(transformedImage.Image)).Item1; Bitmap RedEdgeImage = ImageProcessing.LaplaceEdge(new Bitmap(transformedImage.Image)); double[,] Redpixels2 = ImageProcessing.ConvertToMatrix2(RedEdgeImage).Item1; int RedNumOfTree = Scrambled_Watermark.Count / 5; RedAdaptiveHVS = Embed.AdaptiveHVS(Red_Coeffs, Redpixels, Redpixels2, RedNumOfTree); #endregion #region Green Adaptive HVS double[,] GreenHVSValues = new double[Green_Coeffs.GetLength(0), Green_Coeffs.GetLength(1)]; double[,] GreenAdaptiveHVS = new double[Green_Coeffs.GetLength(0), Green_Coeffs.GetLength(1)]; double[,] Greenpixels = ImageProcessing.ConvertToMatrix2(new Bitmap(transformedImage.Image)).Item2; Bitmap GreenEdgeImage = ImageProcessing.LaplaceEdge(new Bitmap(transformedImage.Image)); double[,] Greenpixels2 = ImageProcessing.ConvertToMatrix2(GreenEdgeImage).Item2; int GreenNumOfTree = Scrambled_Watermark.Count / 5; GreenAdaptiveHVS = Embed.AdaptiveHVS(Green_Coeffs, Greenpixels, Greenpixels2, GreenNumOfTree); #endregion #region Blue Adaptive HVS double[,] BlueHVSValues = new double[Blue_Coeffs.GetLength(0), Blue_Coeffs.GetLength(1)]; double[,] BlueAdaptiveHVS = new double[Blue_Coeffs.GetLength(0), Blue_Coeffs.GetLength(1)]; double[,] Bluepixels = ImageProcessing.ConvertToMatrix2(new Bitmap(transformedImage.Image)).Item3; Bitmap BlueEdgeImage = ImageProcessing.LaplaceEdge(new Bitmap(transformedImage.Image)); double[,] Bluepixels2 = ImageProcessing.ConvertToMatrix2(BlueEdgeImage).Item3; int BlueNumOfTree = Scrambled_Watermark.Count / 5; BlueAdaptiveHVS = Embed.AdaptiveHVS(Blue_Coeffs, Bluepixels, Bluepixels2, BlueNumOfTree); #endregion string subband = subbandValue.Text; double embed_constant = Convert.ToDouble(embedConstantValue.Text); //double[,] EmbeddedWatermark = Embed.Embedding(Wavelet_Coefficients,MappedWatermark, AdaptiveHVS, subband ,embed_constant); double[,] RedEmbeddedWatermark = Embed.Embedding(Red_Coeffs, MappedWatermark, RedAdaptiveHVS, subband, embed_constant); double[,] GreenEmbeddedWatermark = Embed.Embedding(Green_Coeffs, MappedWatermark, GreenAdaptiveHVS, subband, embed_constant); double[,] BlueEmbeddedWatermark = Embed.Embedding(Blue_Coeffs, MappedWatermark, BlueAdaptiveHVS, subband, embed_constant); RedEmbedded_Wavelet_Coefficients = RedEmbeddedWatermark; GreenEmbedded_Wavelet_Coefficients = GreenEmbeddedWatermark; BlueEmbedded_Wavelet_Coefficients = BlueEmbeddedWatermark; GUIEnd("Embedding Succeed!", 0, 0, 0); #endregion } else { #region Edge Based Model GUIStart("Processing.....!"); List<List<int>> Segmented = Scramble.Segment(Scrambled_Watermark); //double[,] MappedWatermark = Scramble.Mapping(Segmented); // Use mapping into 15 bit each 5 segment of scrambled watermark double[,] MappedWatermark = Scramble.Mapping2(Segmented); // Don't Use mapping Mapped_Watermark = MappedWatermark; #region Red Adaptive HVS double[,] RedEdgeHVS = Embed.EdgeBasedHVS(new Bitmap(transformedImage.Image)).Item1; #endregion #region Green Adaptive HVS double[,] GreenHVS = Embed.EdgeBasedHVS(new Bitmap(transformedImage.Image)).Item2; #endregion #region Blue Adaptive HVS double[,] BlueHVS = Embed.EdgeBasedHVS(new Bitmap(transformedImage.Image)).Item3; #endregion string subband = subbandValue.Text; double embed_constant = Convert.ToDouble(embedConstantValue.Text); //double[,] EmbeddedWatermark = Embed.Embedding(Wavelet_Coefficients,MappedWatermark, AdaptiveHVS, subband ,embed_constant); double[,] RedEmbeddedWatermark = Embed.Embedding(Red_Coeffs, MappedWatermark, RedEdgeHVS, subband, embed_constant); double[,] GreenEmbeddedWatermark = Embed.Embedding(Green_Coeffs, MappedWatermark, GreenHVS, subband, embed_constant); double[,] BlueEmbeddedWatermark = Embed.Embedding(Blue_Coeffs, MappedWatermark, BlueHVS, subband, embed_constant); RedEmbedded_Wavelet_Coefficients = RedEmbeddedWatermark; GreenEmbedded_Wavelet_Coefficients = GreenEmbeddedWatermark; BlueEmbedded_Wavelet_Coefficients = BlueEmbeddedWatermark; GUIEnd("Embedding Succeed!", 0, 0, 0); #endregion } } #endregion #region IDWT if (dwtTypeValue.Text == "Haar") { if (transformedImage.Image == null) { MessageBox.Show("There is no Transformed image yet", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else { GUIStart("Processing.....!"); //int level = Convert.ToInt32(HVSValue.Text); //MessageBox.Show("Embedded Wavelet Coefficients: "+Embedded_Wavelet_Coefficients[0,0],"blabal",MessageBoxButtons.OK); //double[,] InverseDWT = Haar.WaveletCoeff(Embedded_Wavelet_Coefficients, false, level); double[,] RedInverseDWT = Haar.WaveletCoeff(RedEmbedded_Wavelet_Coefficients, false, 2); double[,] GreenInverseDWT = Haar.WaveletCoeff(GreenEmbedded_Wavelet_Coefficients, false, 2); double[,] BlueInverseDWT = Haar.WaveletCoeff(BlueEmbedded_Wavelet_Coefficients, false, 2); /// Round all elements in InverseDWT //double[,] RoundedInversedDWT = Statistic.RoundAll(InverseDWT); //transformedImage.Image = ImageProcessing.ConvertToBitmap(InverseDWT); transformedImage.Image = ImageProcessing.ConvertToBitmap2(RedInverseDWT, GreenInverseDWT, BlueInverseDWT); double mse = Statistic.MSE(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); double psnr = Statistic.PSNR(new Bitmap(transformedImage.Image), mse); double ber = Statistic.BER(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); GUIEnd("IDWT Succeed!", mse, psnr, ber); /// Test //double[,] WC = DWT.WaveletCoeff(InverseDWT, true, 2); /// Test //int h = 1; //TextWriter tw1 = new StreamWriter("InversedDWT.txt"); //tw1.WriteLine("Total Watermark: " + InverseDWT.GetLength(0)); //for (int i = 0; i < InverseDWT.GetLength(0); i++) //{ // for (int j = 0; j < InverseDWT.GetLength(1); j++) // { // tw1.Write("[" + h + "]" + InverseDWT[i, j] + " # "); // h++; // } // tw1.WriteLine(); //} ////foreach (double i in ExtractedWatermark) ////{ //// tw1.WriteLine(i); ////} //tw1.Close(); ///Activate Attack Button //histeqBtn.Enabled = true; //histeqBtn.BackColor = Color.DeepSkyBlue; //meanFilterBtn.Enabled = true; //meanFilterBtn.BackColor = Color.DeepSkyBlue; //medianFilterBtn.Enabled = true; //medianFilterBtn.BackColor = Color.DeepSkyBlue; //modusFilterBtn.Enabled = true; //modusFilterBtn.BackColor = Color.DeepSkyBlue; //jpegencoderBtn.Enabled = true; //jpegencoderBtn.BackColor = Color.DeepSkyBlue; resultLbl.Text = "Haar Watermarked Host Image"; WatermarkedImage = new Bitmap(transformedImage.Image); Transformed_Image = new Bitmap(transformedImage.Image); double psnrvalue = Math.Round(psnr, 2); //double bervalue = Math.Round(psnr, 2); double msevalue = Math.Round(psnr, 2); psnrtxt.Text += ">" + file_name + "\n" + "PSNR:" + psnrvalue + "\n" + "Key is saved!" + "\n" + "-----------" + "\n"; dwtTypeValue2.Text = dwtTypeValue.Text; embedConstantValue2.Text = embedConstantValue.Text; subbandValue2.Text = subbandValue.Text; drawing = new Bitmap(transformedImage.Image); reuse = new Bitmap(transformedImage.Image); //test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); } } else if (dwtTypeValue.Text == "Db2") { if (transformedImage.Image == null) { MessageBox.Show("There is no Transformed image yet", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else { GUIStart("Processing.....!"); //int level = Convert.ToInt32(HVSValue.Text); //MessageBox.Show("Embedded Wavelet Coefficients: "+Embedded_Wavelet_Coefficients[0,0],"blabal",MessageBoxButtons.OK); //double[,] InverseDWT = Haar.WaveletCoeff(Embedded_Wavelet_Coefficients, false, level); double[,] RedInverseDWT = Daubechies2.WaveletCoeff(RedEmbedded_Wavelet_Coefficients, false, 2); double[,] GreenInverseDWT = Daubechies2.WaveletCoeff(GreenEmbedded_Wavelet_Coefficients, false, 2); double[,] BlueInverseDWT = Daubechies2.WaveletCoeff(BlueEmbedded_Wavelet_Coefficients, false, 2); /// Round all elements in InverseDWT //double[,] RoundedInversedDWT = Statistic.RoundAll(InverseDWT); //transformedImage.Image = ImageProcessing.ConvertToBitmap(InverseDWT); transformedImage.Image = ImageProcessing.ConvertToBitmap2(RedInverseDWT, GreenInverseDWT, BlueInverseDWT); double mse = Statistic.MSE(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); double psnr = Statistic.PSNR(new Bitmap(transformedImage.Image), mse); double ber = Statistic.BER(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); GUIEnd("IDWT Succeed!", mse, psnr, ber); /// Test //double[,] WC = DWT.WaveletCoeff(InverseDWT, true, 2); /// Test //int h = 1; //TextWriter tw1 = new StreamWriter("InversedDWT.txt"); //tw1.WriteLine("Total Watermark: " + InverseDWT.GetLength(0)); //for (int i = 0; i < InverseDWT.GetLength(0); i++) //{ // for (int j = 0; j < InverseDWT.GetLength(1); j++) // { // tw1.Write("[" + h + "]" + InverseDWT[i, j] + " # "); // h++; // } // tw1.WriteLine(); //} ////foreach (double i in ExtractedWatermark) ////{ //// tw1.WriteLine(i); ////} //tw1.Close(); ///Activate Attack Button //histeqBtn.Enabled = true; //histeqBtn.BackColor = Color.DeepSkyBlue; //meanFilterBtn.Enabled = true; //meanFilterBtn.BackColor = Color.DeepSkyBlue; //medianFilterBtn.Enabled = true; //medianFilterBtn.BackColor = Color.DeepSkyBlue; //modusFilterBtn.Enabled = true; //modusFilterBtn.BackColor = Color.DeepSkyBlue; //jpegencoderBtn.Enabled = true; //jpegencoderBtn.BackColor = Color.DeepSkyBlue; resultLbl.Text = " Daubechies 2 Watermarked Host Image"; WatermarkedImage = new Bitmap(transformedImage.Image); Transformed_Image = new Bitmap(transformedImage.Image); double psnrvalue = Math.Round(psnr, 2); //double bervalue = Math.Round(psnr, 2); double msevalue = Math.Round(psnr, 2); psnrtxt.Text += ">" + file_name + "\n" + "PSNR:" + psnrvalue + "\n" + "Key is saved!" + "\n" + "-----------" + "\n"; dwtTypeValue2.Text = dwtTypeValue.Text; embedConstantValue2.Text = embedConstantValue.Text; subbandValue2.Text = subbandValue.Text; drawing = new Bitmap(transformedImage.Image); reuse = new Bitmap(transformedImage.Image); //test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); } } else { GUIStart("Processing.....!"); //int level = Convert.ToInt32(HVSValue.Text); //MessageBox.Show("Embedded Wavelet Coefficients: "+Embedded_Wavelet_Coefficients[0,0],"blabal",MessageBoxButtons.OK); //double[,] InverseDWT = Haar.WaveletCoeff(Embedded_Wavelet_Coefficients, false, level); double[,] RedInverseDWT = Daubechies3.WaveletCoeff(RedEmbedded_Wavelet_Coefficients, false, 2); double[,] GreenInverseDWT = Daubechies3.WaveletCoeff(GreenEmbedded_Wavelet_Coefficients, false, 2); double[,] BlueInverseDWT = Daubechies3.WaveletCoeff(BlueEmbedded_Wavelet_Coefficients, false, 2); /// Round all elements in InverseDWT //double[,] RoundedInversedDWT = Statistic.RoundAll(InverseDWT); //transformedImage.Image = ImageProcessing.ConvertToBitmap(InverseDWT); transformedImage.Image = ImageProcessing.ConvertToBitmap2(RedInverseDWT, GreenInverseDWT, BlueInverseDWT); double mse = Statistic.MSE(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); double psnr = Statistic.PSNR(new Bitmap(transformedImage.Image), mse); double ber = Statistic.BER(new Bitmap(hostImage.Image), new Bitmap(transformedImage.Image)); GUIEnd("IDWT Succeed!", mse, psnr, ber); /// Test //double[,] WC = DWT.WaveletCoeff(InverseDWT, true, 2); /// Test //int h = 1; //TextWriter tw1 = new StreamWriter("InversedDWT.txt"); //tw1.WriteLine("Total Watermark: " + InverseDWT.GetLength(0)); //for (int i = 0; i < InverseDWT.GetLength(0); i++) //{ // for (int j = 0; j < InverseDWT.GetLength(1); j++) // { // tw1.Write("[" + h + "]" + InverseDWT[i, j] + " # "); // h++; // } // tw1.WriteLine(); //} ////foreach (double i in ExtractedWatermark) ////{ //// tw1.WriteLine(i); ////} //tw1.Close(); ///Activate Attack Button //histeqBtn.Enabled = true; //histeqBtn.BackColor = Color.DeepSkyBlue; //meanFilterBtn.Enabled = true; //meanFilterBtn.BackColor = Color.DeepSkyBlue; //medianFilterBtn.Enabled = true; //medianFilterBtn.BackColor = Color.DeepSkyBlue; //modusFilterBtn.Enabled = true; //modusFilterBtn.BackColor = Color.DeepSkyBlue; //jpegencoderBtn.Enabled = true; //jpegencoderBtn.BackColor = Color.DeepSkyBlue; resultLbl.Text = " Daubechies 2 Watermarked Host Image"; WatermarkedImage = new Bitmap(transformedImage.Image); Transformed_Image = new Bitmap(transformedImage.Image); double psnrvalue = Math.Round(psnr, 2); //double bervalue = Math.Round(psnr, 2); double msevalue = Math.Round(psnr, 2); psnrtxt.Text += ">" + file_name + "\n" + "PSNR:" + psnrvalue + "\n" + "Key is saved!" + "\n" + "-----------" + "\n"; dwtTypeValue2.Text = dwtTypeValue.Text; embedConstantValue2.Text = embedConstantValue.Text; subbandValue2.Text = subbandValue.Text; drawing = new Bitmap(transformedImage.Image); reuse = new Bitmap(transformedImage.Image); //test //MessageBox.Show("Red: " + IMatrixR[0, 0].ToString() + ", Green: " + IMatrixG[0, 0].ToString() + ", Blue: " + IMatrixB[0, 0].ToString(), "Values of RGB"); } #endregion }
/// <summary> /// Scramble the watermark bits /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e/*,double[,] coeffs*/) //Generate bit sequence contain 0 and 1 { if (watermarkImage.Image == null) { MessageBox.Show("Load Watermark Image First!", "Incomplete Procedure Detected!", MessageBoxButtons.OK); } else { if(seedValue.Text.Length > 5 || seedValue.Text == null) { MessageBox.Show("Maximum length of Key is 5 or cannot be empty"); }else { GUIStart("Processing......!"); //double[,] coefficients = coeffs; Bitmap bmp = new Bitmap(watermarkImage.Image); Scramble m = new Scramble(); Bitmap b = ImageProcessing.ConvertToBinary(bmp); List<int> VectorImage = Scramble.ConvertToVectorMatrix(b); //Include integer values between 255 or 0 List<int> BinaryVectorImage = Scramble.ConvertToBinaryVectorMatrix(VectorImage); //Include integer values between 1 or 0 Real_Watermark = BinaryVectorImage; int pnlength = BinaryVectorImage.Count * 5; string pn_seed = seedValue.Text;//"10000"; string pn_mask = "10100"; int pn_length = pnlength; List<int> PNSeq = Scramble.PNSeqLFSR(pn_seed, pn_mask, pn_length); List<int> scrambled_Watermark = Scramble.DSSS(BinaryVectorImage, PNSeq); /// Save into .txt file (PN Sequence and size) Bitmap hostbmp = new Bitmap(hostImage.Image); string hostfilename = HostImageLocationTxt.Text; string watermarkfilename = WatermarkImageLocationTxt.Text; string hostName = Path.GetFileNameWithoutExtension(hostfilename); string watermarkName = Path.GetFileNameWithoutExtension(watermarkfilename); string name = hostName + "_" + watermarkName + "_Key.txt"; int NumOfTrees = pnlength / 5; // Restult in total of tree from segmented watermark , i.e 6480 //TextWriter tw = new StreamWriter(name); using (TextWriter tw = File.CreateText(@"F:\College\Semester 8\TA2\TugasAkhir1\TugasAkhir1\Key\" + name)) { tw.WriteLine("Size of Host Image:"); tw.WriteLine(hostbmp.Height); tw.WriteLine(hostbmp.Width); tw.WriteLine("Size of Watermark: "); tw.WriteLine(bmp.Height); tw.WriteLine(bmp.Width); tw.WriteLine("Number of Trees: "); tw.WriteLine(NumOfTrees); tw.WriteLine("PN Sequence: "); foreach (int i in PNSeq) { tw.WriteLine(i); } tw.Close(); } //List<int> oneminusone = Scramble.ConvertTo1minus1(scrambled_Watermark); Scrambled_Watermark = scrambled_Watermark; //Scrambled_Watermark = oneminusone; GUIEnd("Scramble Succeed!", 0, 0, 0); //MessageBox.Show("Watermark is Succeed. File Was Saved \n Original Watermark: " + BinaryVectorImage.Count + "\n Scrambled Watermark: " + scrambled_Watermark.Count + "\n PN Sequence: " + PNSeq.Count, "Succeed", MessageBoxButtons.OK); //TextWriter tw1 = new StreamWriter("REAL_WATERMARK.txt"); //tw1.WriteLine("Total Real Watermark: " + BinaryVectorImage.Count); //foreach (int i in BinaryVectorImage) // tw1.WriteLine(i); //tw1.Close(); //TextWriter tw2 = new StreamWriter("SCRAMBLED_WATERMARK.txt"); //tw2.WriteLine("Total Scrambled Watermark: " + Scrambled_Watermark.Count); //foreach (int i in Scrambled_Watermark) // tw2.WriteLine(i); //tw2.Close(); //TextWriter tw3 = new StreamWriter("PN_Sequence.txt"); //tw3.WriteLine("Total PN Sequence Watermark: " + PNSeq.Count); //foreach (int i in PNSeq) // tw3.WriteLine(i); //tw3.Close(); } } }