Deteksi Tepi Analisis Perbandingan Geometric Mean Filter Dengan Operator Sobel, Operator Prewitt Dan Operator Robert Pada Citra Bitmap

{ x1 = rand.Next0,x-1; y1 = rand.Next0,y-1; val = rand.Next1,10; if val = 5 { citraHasil.SetPixelx1,y1,Color.FromArgb255,0,0,0; } else { citraHasil.SetPixelx1,y1,Color.FromArgb255,255,255, 255; } } pcitraNoise.Image=citraAsli; } void Button1Clickobject sender, EventArgs e { ifpcitraNoise.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pcitraNoise.Image.Savesave.FileName, System.Drawing. Imaging.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } } }

3. Deteksi Tepi

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Diagnostics; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace AnalisisPerbandinganFilertingdanDeteksiTepi { public partial class DeteksiTepi : Form { Bitmap img; public DeteksiTepi { InitializeComponent; } void HomeToolStripMenuItemClickobject sender, EventArgs e { MainForm ua = new MainForm; this.Hide; ua.ShowDialog ; } void FilteringToolStripMenuItemClickobject sender, EventArgs e { Filtering us = new Filtering; this.Hide; us.ShowDialog; } void AboutToolStripMenuItemClickobject sender, EventArgs e { Help uf = new Help; this.Hide; uf.ShowDialog; } void AboutToolStripMenuItem1Clickobject sender, EventArgs e { About ug = new About; this.Hide; ug.ShowDialog; } void PictureBox5Clickobject sender, EventArgs e { try { OpenFileDialog oFile = new OpenFileDialog; oFile.Filter = Images File.bmp|.bmp; if oFile.ShowDialog == DialogResult.OK { Bitmap cit = new Bitmap oFile.FileName; if cit.Height = 300 cit.Width = 300 { citraAsli.Image = cit; img = new Bitmapnew BitmapoFile.FileName, citraAsli.Width, citraAsli.Height; citraAsli.Image = img; textBox1.Text=cit.Width.ToString; textBox2.Text=cit.Height.ToString; textBox3.Text=oFile.SafeFileName.ToString; } else MessageBox.ShowImage Pixel must be 300x300, Warning; } } catch Exception { throw new ApplicationExceptionFailed Loading ; } } void PictureBox8Clickobject sender, EventArgs e { try { OpenFileDialog oFile = new OpenFileDialog; oFile.Filter = Images File.bmp|.bmp; if oFile.ShowDialog == DialogResult.OK { Bitmap cit = new Bitmap oFile.FileName; if cit.Height = 300 cit.Width = 300 { citraFiltering.Image = cit; img = new Bitmapnew BitmapoFile.FileName, citraFiltering.Width, citraFiltering .Height; citraFiltering.Image = img; textBox9.Text=cit.Width.ToString; textBox7.Text=cit.Height.ToString; textBox8.Text=oFile.SafeFileName.ToString; } else MessageBox.ShowImage Pixel must be 300x300, Warning; } } catch Exception { throw new ApplicationExceptionFailed Loading ; } } void ClearDeteksiClickobject sender, EventArgs e { citraAsli.Image=null; citraFiltering.Image=null; pSobel.Image=null; pRobert.Image=null; pPrewitt.Image=null; pfSobel.Image=null; pfPrewitt.Image=null; pfRobert.Image=null; textBox1.Text=null;textBox2.Text=null;textBox3.Text=null; textBox7.Text=null;textBox8.Text=null;textBox9.Text=null; textBoxs1.Text=null;textBoxs2.Text=null;textBoxs3.Text=null; textBoxs4.Text=null;textBoxs5.Text=null;textBoxs6.Text=null; textBoxp1.Text=null;textBoxp2.Text=null;textBoxp3.Text=null; textBoxp4.Text=null;textBoxp5.Text=null;textBoxp6.Text=null; textBoxr1.Text=null;textBoxr2.Text=null;textBoxr3.Text=null; textBoxr4.Text=null;textBoxr5.Text=null;textBoxr6.Text=null; } void ExitToolStripMenuItemClickobject sender, EventArgs e { if MessageBox.ShowAre you sure to exit the Aplication?, Exit, MessageBoxButtons.YesNo, MessageBoxIcon.Question == DialogResult.Yes Application.Exit; } private Bitmap SobelEdgeDetectBitmap original { Bitmap sobel = new Bitmaporiginal; int [,] arr_r; int [,] arr_g; int [,] arr_b; byte[,] temp_array; arr_r = new int[sobel.Width, sobel.Height]; arr_g = new int[sobel.Width, sobel.Height]; arr_b = new int[sobel.Width, sobel.Height]; temp_array=new byte[sobel.Width, sobel.Height]; double x; double y; double grad; for int i = 1; i sobel.Width - 1; i++ { for int j = 1; j sobel.Height - 1; j++ { arr_r[i, j] = original.GetPixeli, j.R; arr_g[i, j] = original.GetPixeli, j.G; arr_b[i, j] = original.GetPixeli, j.B; arr_r[i, j] = arr_r[i, j] + arr_g[i, j] + arr_b[i, j] 3; } } for int i = 1; i sobel.Width-1; i++ { for int j = 1; j sobel.Height-1; j++ { x=System.Math.Abs1arr_r[i-1,j-1]+2arr_r[i- 1,j] + 1arr_r[i-1,j+1] - arr_r[i+1, j-1] - 2 arr_r[i+1, j] - arr_r[i + 1, j + 1]; y=System.Math.Abs1arr_r[i-1,j-1]+2arr_r[i,j- 1]+1arr_r[i+1,j-1]-1arr_r[i-1,j+1]-2arr_r[i,j+1]-1arr_r[i+1,j+1]; grad = System.Math.Sqrtxx+yy; if grad 255 grad =255; temp_array[i, j] =bytegrad; sobel.SetPixeli,j,Color.FromArgbtemp_array[i, j],tem p_array[i, j],temp_array[i,j]; } } return sobel; } private Bitmap PrewittEdgeDetectBitmap original { Bitmap prewitt = new Bitmaporiginal; int [,] arr_r; int [,] arr_g; int [,] arr_b; byte[,] temp_array; arr_r = new int[prewitt.Width, prewitt.Height]; arr_g = new int[prewitt.Width, prewitt.Height]; arr_b = new int[prewitt.Width, prewitt.Height]; temp_array=new byte[prewitt.Width, prewitt.Height]; double x; double y; double grad; for int i = 1; i prewitt.Width - 1; i++ { for int j = 1; j prewitt.Height - 1; j++ { arr_r[i, j] = original.GetPixeli, j.R; arr_g[i, j] = original.GetPixeli, j.G; arr_b[i, j] = original.GetPixeli, j.B; arr_r[i, j] = arr_r[i, j] + arr_g[i, j] + arr_b[i, j] 3; } } for int i = 1; i prewitt.Width-1; i++ { for int j = 1; j prewitt.Height-1; j++ { x=System.Math.Abs1arr_r[i-1,j-1]+1arr_r[i- 1,j] + 1arr_r[i-1,j+1] - 1 arr_r[i+1, j-1] - 1 arr_r[i+1, j] - 1arr_r[i + 1, j + 1]; y=System.Math.Abs1arr_r[i-1,j-1]+1arr_r[i,j- 1]+1arr_r[i+1,j-1]-1arr_r[i-1,j+1]-1arr_r[i,j+1]-1arr_r[i+1,j+1]; grad = System.Math.Sqrtxx+yy; if grad 255 grad =255; temp_array[i, j] =bytegrad; prewitt.SetPixeli,j,Color.FromArgbtemp_array[i, j],t emp_array[i, j],temp_array[i,j]; } } return prewitt; } private Bitmap RobertEdgeDetectBitmap original { Bitmap robert = new Bitmaporiginal; int [,] arr_r; int [,] arr_g; int [,] arr_b; byte[,] temp_array; arr_r = new int[robert.Width, robert.Height]; arr_g = new int[robert.Width, robert.Height]; arr_b = new int[robert.Width, robert.Height]; temp_array=new byte[robert.Width, robert.Height]; double x; double y; double grad; for int i = 1; i robert.Width - 1; i++ { for int j = 1; j robert.Height - 1; j++ { arr_r[i, j] = original.GetPixeli, j.R; arr_g[i, j] = original.GetPixeli, j.G; arr_b[i, j] = original.GetPixeli, j.B; arr_r[i, j] = arr_r[i, j] + arr_g[i, j] + arr_b[i, j] 3; } } for int i = 0; i robert.Width-1; i++ { for int j = 0; j robert.Height-1; j++ { x=System.Math.Absarr_r[i, j] - arr_r[i + 1, j + 1]; y=System.Math.Absarr_r[i + 1, j] - arr_r[i, j + 1]; grad = x+y; if grad 255 grad =255; temp_array[i, j] =bytegrad; robert.SetPixeli,j,Color.FromArgbtemp_array[i, j],te mp_array[i, j],temp_array[i,j]; } } return robert; } void RobertFilterClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraFiltering.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pfRobert.Image=RobertEdgeDetectimageHasil; time.Stop; textBoxr6.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxr4.Text = hitungMSEBitmapcitraFiltering.Image,BitmappfRobert.Image.ToString; textBoxr5.Text = hitungPSNRConvert.ToDoubletextBoxr4.Text.ToString; } void SaveroberClickobject sender, EventArgs e { ifpRobert.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pRobert.Image.Savesave.FileName, System.Drawing.Imag ing.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SaveSobelClickobject sender, EventArgs e { ifpSobel.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pSobel.Image.Savesave.FileName, System.Drawing.Imagi ng.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SavePrewittClickobject sender, EventArgs e { ifpPrewitt.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pPrewitt.Image.Savesave.FileName, System.Drawing .Imaging.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SfSobelClickobject sender, EventArgs e { ifpfSobel.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pfSobel.Image.Savesave.FileName, System.Drawing. Imaging.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SfPrewittClickobject sender, EventArgs e { ifpfPrewitt.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pfPrewitt.Image.Savesave.FileName, System.Drawin g.Imaging.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } double hitungMSEBitmap imageAsli, Bitmap imageHasil { double sum = 0; double pxAsli; double pxHasil; double MSE; for int i = 0; i imageAsli.Height; i++ { for int j = 0; j imageAsli.Width; j++ { pxAsli = imageAsli.GetPixelj, i.R; pxHasil = imageHasil.GetPixelj, i.R; sum += Math.PowpxAsli - pxHasil, 2; } } MSE = sum imageAsli.Height imageAsli.Width; return MSE; } double hitungPSNR double MSE { double PSNR = Math.Log10Math.Pow255, 2MSE; return PSNR; } void PrewittClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraAsli.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pPrewitt.Image=PrewittEdgeDetectimageHasil; time.Stop; textBoxp3.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxp1.Text = hitungMSEBitmapcitraAsli.Image,BitmappPrewitt.Image.ToString; textBoxp2.Text = hitungPSNRConvert.ToDoubletextBoxp1.Text.ToString; } void SobelClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraAsli.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pSobel.Image=SobelEdgeDetectimageHasil; time.Stop; textBoxs3.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxs1.Text = hitungMSEBitmapcitraAsli.Image,BitmappSobel.Image.ToString; textBoxs2.Text = hitungPSNRConvert.ToDoubletextBoxs1.Text.ToString; } void Button1Clickobject sender, EventArgs e { ifpSobel.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pSobel.Image.Savesave.FileName, System.Drawing.Imagi ng.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SobelFilterClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraFiltering.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pfSobel.Image=SobelEdgeDetectimageHasil; time.Stop; textBoxs6.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxs4.Text = hitungMSEBitmapcitraFiltering.Image,BitmappfSobel.Image.ToString; textBoxs5.Text = hitungPSNRConvert.ToDoubletextBoxs4.Text.ToString; } void PrewittFilterClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraFiltering.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pfPrewitt.Image=PrewittEdgeDetectimageHasil; time.Stop; textBoxp6.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxp4.Text = hitungMSEBitmapcitraFiltering.Image,BitmappfPrewitt.Image.ToString; textBoxp5.Text = hitungPSNRConvert.ToDoubletextBoxp4.Text.ToString; } void SfrobertClickobject sender, EventArgs e { ifpfRobert.Image = null { SaveFileDialog save = new SaveFileDialog; save.Filter = Image Files | .bmp; save.FileName = .bmp; if save.ShowDialog == DialogResult.OK { pfRobert.Image.Savesave.FileName, System.Drawing.Ima ging.ImageFormat.Bmp; MessageBox.Showimage save , save, MessageBoxButtons.OK, MessageBoxIcon.Information; } else { MessageBox.Showerror save ; } } } void SaveRobertClickobject sender, EventArgs e { Stopwatch time = new Stopwatch; time.Start; Bitmap bit = new BitmapcitraAsli.Image; int x = bit.Height; int y = bit.Width; double rd=0,bl=0,gr=0,gy=0; Bitmap imageHasil = new Bitmapx,y; for int i = 0; i x-1; i++ { for int j = 0; j = y-1; j++ { rd = bit.GetPixeli,j.R; if rd =0 rd = 255; gr = bit.GetPixeli,j.G; bl = bit.GetPixeli,j.B; gy = rd0.3 + gr0.59 + bl0.11; imageHasil.SetPixeli,j,Color.FromArgbintgy,intgy,i ntgy; gy = 0; } } pRobert.Image=RobertEdgeDetectimageHasil; time.Stop; textBoxr3.Text = Math.RoundConvert.ToDecimaltime.ElapsedMilliseconds1000,4.ToString; textBoxr1.Text = hitungMSEBitmapcitraAsli.Image,BitmappRobert.Image.ToString; textBoxr2.Text = hitungPSNRConvert.ToDoubletextBoxr1.Text.ToString; } } }

4. Help.cs