Anda di halaman 1dari 5

Dalam tutorial C# kali ini akan mengulas mengenai bagaimana merancang

project deteksi tepian citra (edge detection) dengan algorithm Sobel dalam
digital image processing, pengolahan citra digital, dengan menggunakan
framework AForge.

Sebelumnya perlu diingat untuk install terlebih dahulu AForge, kemudian


tambahkan file reference yang diperlukan, yakni dengan cara pilih tab PROJECT
kemudian Add Reference, bisa juga pada Solution Explorer pilih References
kemudian klik kanan dan Add Reference. Setelah itu akan tampil window
pencarian file yang diperlukan. Untuk project ini gunakan AForge.dll dan
AForge.Imaging.dll.
Komponen yang digunakan.

MenuStrip menuStrip1
PictureBox initialPicture
PictureBox filteredPicture
OpenFileDialog openFileDialog1

Untuk source code yang digunakan ialah sebagai berikut.


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;

namespace edgeDetectionSobel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void clearChecked()
{
normalToolStripMenuItem.Checked = false;
fitToolStripMenuItem.Checked = false;
stretchedToolStripMenuItem.Checked = false;
centeredToolStripMenuItem.Checked = false;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
FileDialog fileDialog = new OpenFileDialog();
fileDialog.ShowDialog(this);
string fileName = fileDialog.FileName;
if (fileName == string.Empty) return;
initialPicture.Image = System.Drawing.Image.FromFile(fileName);
sizeToolStripMenuItem.Enabled = (initialPicture.Image != null);
filterToolStripMenuItem.Enabled = (initialPicture.Image != null);
}
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
initialPicture.SizeMode = PictureBoxSizeMode.Normal;
filteredPicture.SizeMode = PictureBoxSizeMode.Normal;
normalToolStripMenuItem.Checked = true;
}
private void fitToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
initialPicture.SizeMode = PictureBoxSizeMode.Zoom;
filteredPicture.SizeMode = PictureBoxSizeMode.Zoom;
fitToolStripMenuItem.Checked = true;
}
private void stretchedToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
initialPicture.SizeMode = PictureBoxSizeMode.StretchImage;
filteredPicture.SizeMode = PictureBoxSizeMode.StretchImage;
stretchedToolStripMenuItem.Checked = true;
}
private void centeredToolStripMenuItem_Click(object sender, EventArgs e)
{
clearChecked();
initialPicture.SizeMode = PictureBoxSizeMode.CenterImage;
filteredPicture.SizeMode = PictureBoxSizeMode.CenterImage;
centeredToolStripMenuItem.Checked = true;

}
private void filterToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap image = new Bitmap(initialPicture.Image);
IFilter filter = new SobelEdgeDetector();
image = Grayscale.CommonAlgorithms.RMY.Apply(image);
image = filter.Apply(image);
filteredPicture.Image = image;
}
}
}

Edge detection is the name for a set of mathematical methods which aim at
identifying points in a digital image at which the image brightness changes
sharply or, more formally, has discontinuities. The points at which image
brightness changes sharply are typically organized into a set of curved line
segments termed edges. The same problem of finding discontinuities in 1D
signals is known as step detection and the problem of finding signal
discontinuities over time is known as change detection. Edge detection is a
fundamental tool in image processing, machine vision and computer vision,
particularly in the areas of feature detection and feature extraction.
The purpose of detecting sharp changes in image brightness is to capture
important events and changes in properties of the world. It can be shown that
under rather general assumptions for an image formation model, discontinuities
in image brightness are likely to correspond to:

Discontinuities in depth
Discontinuities in surface orientation
Changes in material properties
Variations in scene illumination

In the ideal case, the result of applying an edge detector to an image may lead
to a set of connected curves that indicate the boundaries of objects, the
boundaries of surface markings as well as curves that correspond to
discontinuities in surface orientation. Thus, applying an edge detection algorithm
to an image may significantly reduce the amount of data to be processed and
may therefore filter out information that may be regarded as less relevant, while
preserving the important structural properties of an image. If the edge detection
step is successful, the subsequent task of interpreting the information contents
in the original image may therefore be substantially simplified. However, it is not
always possible to obtain such ideal edges from real life images of moderate
complexity.
Edges extracted from non-trivial images are often hampered by fragmentation,
meaning that the edge curves are not connected, missing edge segments as well
as false edges not corresponding to interesting phenomena in the image thus
complicating the subsequent task of interpreting the image data.
Edge detection is one of the fundamental steps in image processing, image
analysis, image pattern recognition, and computer vision techniques.

Sobel Operator
Brief Description

The Sobel operator performs a 2-D spatial gradient measurement on an image


and so emphasizes regions of high spatial frequency that correspond to edges.
Typically it is used to find the approximate absolute gradient magnitude at each
point in an input grayscale image. The gradient of the image is calculated for
each pixel position in the image.

History
The Sobel operator, sometimes called the SobelFeldman operator or Sobel filter,
is used in image processing and computer vision, particularly within edge
detection algorithms where it creates an image emphasising edges. It is named
after Irwin Sobel and Gary Feldman, colleagues at the Stanford Artificial
Intelligence Laboratory, SAIL. It was co-developed with Gary Feldman at SAIL.
Sobel and Feldman presented the idea of an "Isotropic 3x3 Image Gradient
Operator" at a talk at SAIL in 1968. Technically, it is a discrete differentiation
operator, computing an approximation of the gradient of the image intensity
function. At each point in the image, the result of the SobelFeldman operator is
either the corresponding gradient vector or the norm of this vector. The Sobel
Feldman operator is based on convolving the image with a small, separable, and
integer-valued filter in the horizontal and vertical directions and is therefore
relatively inexpensive in terms of computations. On the other hand, the gradient
approximation that it produces is relatively crude, in particular for high-frequency
variations in the image.

Anda mungkin juga menyukai