Perbandingan Hasil Deteksi Tepi Laplacian Of Gaussian Dengan Laplacian Of Gaussian Kombinasi High Boost Filtering

78

LISTING PROGRAM
1. Form Home

using
using
using
using

System;
System.Collections.Generic;
System.Drawing;
System.Windows.Forms;

namespace Program_Skripsi
{
public partial class MainForm : Form
{
public MainForm()
{

InitializeComponent();
}
//menu untuk masuk ke form pengujian
void PengujianToolStripMenuItemClick(object sender, EventArgs e)
{
FormPengujian f2 = new FormPengujian();
f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke form hasil
void HasilToolStripMenuItemClick(object sender, EventArgs e)
{
FormHasil f2 = new FormHasil();
f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke form help
void HelpToolStripMenuItemClick(object sender, EventArgs e)
{
FormHelp f2 = new FormHelp();

f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke form about
void AboutToolStripMenuItemClick(object sender, EventArgs e)
{
FormAbout f2 = new FormAbout();
f2.ShowDialog();
this.Dispose();
}
//menu untuk keluar dari aplikasi
void ExitToolStripMenuItem1Click(object sender, EventArgs e)
{
if (MessageBox.Show("Keluar Aplilkasi?", "Keluar",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)

79

== DialogResult.Yes)
Application.Exit();

}
}
}

2. Form Pengujian

using
using
using
using
using
using
using
using
using
using
using
using

System;

System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Drawing.Imaging;
System.Linq;
System.Text;
System.Windows.Forms;
System.Runtime.InteropServices;
System.Diagnostics;
System.IO;

namespace Program_Skripsi
{
public partial class FormPengujian : Form
{
bool bitdeviasi;
double Deviasi;
double proba;
IntPtr point = IntPtr.Zero;

int[,] pixelImage;
double[,] tapisHighBoost;
double A;
double w;
double runtime;
//menu untuk masuk ke form home
void HomeToolStripMenuItemClick(object sender, EventArgs e)
{
MainForm f2 = new MainForm();
f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke form pengujian
void HasilToolStripMenuItemClick(object sender, EventArgs e)
{
FormHasil f2 = new FormHasil();
f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke fom help


80

void HelpToolStripMenuItemClick(object sender, EventArgs e)
{
FormHelp f2 = new FormHelp();
f2.ShowDialog();
this.Dispose();
}
//menu untuk masuk ke form about
void AboutToolStripMenuItemClick(object sender, EventArgs e)
{
FormAbout f2 = new FormAbout();
f2.ShowDialog();
this.Dispose();
}
//menu untuk keluar dari aplikasi
void ExitToolStripMenuItemClick(object sender, EventArgs e)
{
if (MessageBox.Show("Keluar Aplilkasi?", "Keluar",

MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.Yes)
Application.Exit();
}

//tombol browse untuk menginput objek
void Button1Click(object sender, EventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Image Files( *.bmp)|*.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
Bitmap bit = new Bitmap(open.FileName);
if (bit.Height 255) newpixel = 255;
Pixels[i + j] = Convert.ToByte(newpixel);
}
}
}

Marshal.Copy(Pixels, 0, point, Pixels.Length);
citraasli.UnlockBits(bmpData);
pictureBox2.Image=citraasli;
pictureBox3.Image=citraasli;
}
}

//tombol radio button untuk memilih Salt and Pepper noise
void RadioButton2CheckedChanged(object sender, EventArgs e)
{
if(radioButton2.Checked)
{
Bitmap citraasli = new Bitmap(pictureBox1.Image);
int x = citraasli.Width;
int y = citraasli.Height;
Bitmap citrahasil = citraasli;
if ((comboBox1.Text) == "10%")
proba = Convert.ToInt32(0.1*x*y);
else if ((comboBox1.Text) == "20%")
proba = Convert.ToInt32(0.2*x*y);

else if ((comboBox1.Text) == "30%")
proba = Convert.ToInt32(0.3*x*y);
else if ((comboBox1.Text) == "40%")
proba = Convert.ToInt32(0.4*x*y);
else if ((comboBox1.Text) == "50%")
proba = Convert.ToInt32(0.5*x*y);
int x1,y1,val;
Random rnd = new Random();
for (int i = 0; i < proba; i++)

83

{
x1 = rnd.Next(0,x-1);
y1 = rnd.Next(0,y-1);
val = rnd.Next(1,10);
if (val d)
{
bitmapPtr[row * offset] = bitmapPtr[row * offset + 1] = bitmapPtr[row
* offset + 2 = 255;

}
else
bitmapPtr[row * offset] = bitmapPtr[row * offset + 1] =
bitmapPtr[row * offset + 2] = 0;
}
}
}
bitmap.UnlockBits(bitmapData);
SrcImage.UnlockBits(srcData);
return bitmap;
}

//tombol radio button untuk memilih operator deteksi tepi Laplacian of
Gaussian
void RadioButton3CheckedChanged(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
sw.Start();
Bitmap citraasli = new Bitmap(pictureBox2.Image);
pictureBox3.Image = LoG12x12(citraasli);

sw.Stop();
runtime = Math.Round(Convert.ToDouble(sw.ElapsedMilliseconds)/1000,4);
}
//fungsi untuk High Boost filtering
private double HighBoost(int x, int y)
{
double Hasil = 0;
int row = x;
int col = y;
for (int i = 0; i < 3; i++)
{
col = y;
for (int j = 0; j < 3; j++)
{
Hasil += pixelImage[row, col] * tapisHighBoost[i, j];
col++;
}

88

row++;
}
double HighBoost = ((A-1)* pixelImage[x, y]) + Hasil;
//MessageBox.Show(pixelImage[x,y].ToString());
return HighBoost;
}
//tombol radio button untuk memilih operator deteksi tepi Laplacian of
Gaussian kombinasi High Boost filtering
void RadioButton5CheckedChanged(object sender, EventArgs e)
{
//Tentukan Tapishighboost
if(radioButton5.Checked)
{
try {
A= Convert.ToDouble(textBox1.Text);
if ( A 255)
pixel = 255;
output.SetPixel(j + 1, i + 1, Color.FromArgb(255, pixel,

89

pixel, pixel));
}
}
pictureBox3.Image = LoG12x12(output);
sw.Stop();
runtime = Math.Round(Convert.ToDouble(sw.ElapsedMilliseconds)/1000,4);
}
else
{
MessageBox.Show("Nilai A harus