You are on page 1of 19

1|Page

Dissertation Report Edge detecting with processing


By Mathew Clewlow
Supervisor: Maziar Nezhad

2|Page

Content
Abstract

pg3

Introduction

pg4

Methodology

pg4

Background

pg5

Conclusion

pg17

Results

pg19

3|Page

Abstract

This paper is to look in to the edge detecting methods and how it's achieved. The background
will look into the different techniques and how they are achieved. The paper will also contain
the programing for the different parts other edge detection process this will then be summed
up in the results section. The conclusion is the paper shows how these techniques can be use
in the real world and some of the point that this paper does not cover and has achieved.

4|Page

Introduction
This paper is an exploration of edge detecting methods and how it's achieved. The Edge
detection is a set of mathematical methods which aim to identify points in a digital image.
The two mathematical methods that are being explored are Laplacian and gradient methods.
This paper will look at some research in to this area, as well as understanding the different
between the different methods and how they achieve and how they are implemented in the
program language. The soft wear that is going to be conceded to implement this is Matlab.
Matlab is a software that lets the user do mathematics, computation, analyse data, and
produce graphical displays. The use of a matrix in Matlab will allow the use to analyses the
image and use it to couple the experiment that this paper is looking at. Edge detecting is the
many early stages of vision processing this helps identify features that are in image. This
helps to estimating the structure and properties of objects in a image. One such feature are
edges. Edges are important changes in images and are important features for analysing
images. Edges usually occur on a boundary between two different areas if an image. The
reason Edge detection is important is because it is the first step in recovering information
from images.
Methodology
The first the program language matlab must be looked at. The program needs to be retain,
this will contain a small part that will take the image from the webcam and display it on the
screen. This part of the program will be that same in both Laplacian and in gradient methods.
Then the programs will be made individually. Each program will be put throw the same
experiments. This then answer that each program has the same noise and errors. To achieve
this some experiments will be use, to compare the different methods. First programs will be
correlated using the same basic programme to create an accurate the picture, this means the

5|Page

noise from the picture will be smaller. The experiment will consist of a USB camera and
some basic shapes, for example circles squares and triangles. The first set of experiments is to
see the ability to detect different shades and the limits. The next is the different colours and
the ability to distinguish between different shades like orange and red for example. The last is
the light over the shapes brighteners will change from bight to dark. If this proves to give
good data on the different methods, then more complex shapes will be considered. The data
will be taken in the off images to visually compare them to see if the image was edge
detected and how sharp the lines are on the image. This image then can be compared to that
of a human. This can be done by gathering a group of human subjects to look at the same
images from the webcam and then asked to draw the edge of the image. This then can show
how a human would look and interpret the command of looking at the edges of images.

Backgrounds
A common perception of a digital image is an image on a screen made out of pixels.
However how are these pictures arranged and how do we get different brightness and
colours? Images are comprised of a coordinate system with the a function of f(x,y). This
coordinate system helps place the pixels in the right area on the image. Each pixel has a
different brightness value depending on where it is on the coordinate system, forming a
matrix system with different value for brightness. If we thought of the system as a three-way
coordinate system using z as brightness then would turn the image into a series of active peak
regions, where brightness changes rapidly or smoothly, with many flat plateaus where
brightness varies very little or was constant. As the image is a matrix of a series of functions
this mean we can use mathematical functions on them to determine different brightness' and

6|Page

peaks and troughs and plateaus. Below are some of the functions that consist in an image in a
2D format, these illustrate the different functions that we will consider.
Edge have many different types. This depend on the image that is in question. Lets examine
the different possibilities that might be found in images.

Figure(1) step function

This is a step function, this type of function occurs when there is a paper change in colour,
like from black to white. This function is found in images that are designed boundaries. This
means on either side of the edge there is a distinct colour or shade change.
The next function is a ramp

Figure(2) ramp function

The ramp function is similar to the step except that the change is more gradual than that of
the slop function. This is found when the change in pixel colour is gradual a transition from
one shade to another. This can be seen in an image shadows or slow change in colour.

7|Page

The next is the ridge function

Figure (3) ridge function

The ridge function is when you have two step functions back to back. This show that there is
distinct line running throw the image or an image out line. This could be a line a black line on
a white background. Where the white meets the black there is a distinct change, so there is a
step function. When the black meet the white there is a distinct change back, this give a step
function but in reverse, this is how the ridge function is formed.
The last function is the roof

Figure(4) ridge function.

This function is similar to the ridge but it more of a gradual slope, so it more like the ridge
with the slope function attached to each side. This is type of function is used when an image
has a line that fades in and then out. This then give use a slope up then down.
The step and ridge function are in images, but they are not used much in edge detecting. This
is due to the use of smoothing filters like the Gaussian. This are used to smooth out the noise
on the image. By smoothing the image and therefore the functions. When the functions are
smoothed because the share rise, like that of the step function, to be smoothed to form a slope
function. The reason for the smoothing it to reduce the noise that can be harmful to the data.

8|Page

Gaussian be for we consider Laplacian and gradient methods; we must look in to the filter the
image. The filter that is in question it that of Gaussian. The reason for a filter is because of
the noise on the images this can affect the results and cause edges to be lost are for false
edges to appear. The Gaussian filter is an impulse response is that of the Gaussian function.
The Gaussian function is given by:

But way use a Gaussian filter and not just a low pass filter? This is due to the smoothing
effect that the Gaussian filter has on the function of the image, whereas the low pass filter
would leave ripples in the function and this may show when the edge detection is impaired.
So this is the reason for Gaussian.
Laplacian
The Lacanian of a 2D function of f(x,y) is of a second order derivatives as the following
equation: 2 f (x,y)=2 f (x,y) x2 +2 f (x,y) y2 the laplacian is really use by itself for edge
detection, this is due to the use of the second order derivative it is unacceptably sensitive to
the noise. However, if the laplacian can be very power full when used with in combination
with other edge detection techniques for example with the Gaussian with the edge detection
in mind how can the used of the powerful equation help. The way to find were place in the
image the intensity changes rapidly the use of two general techniques are used. The first is
the first derivative this allows use to find this show use all the pecks. If the pecks are above a
specified threshold, then this are the edges. When in this form, the edge has a large width, so

9|Page

the second technique is to take are another derivative. This is the second derivative this gives
us the zero crossing. Although now there may be more zero crossing than edges so to find the
real edges the first and second are corner to see were the zero crossing are the same as the
peaks.
Laplacian of Gaussian Now we can consider the laplacian of Gaussian, this is the method of
creating an equation the use both the laplacian and the Gaussian in one equation. This is done
by consider the Gaussian function: h(r)=e r2 2o2 and if we consider that r^2=x^2+y^2 and o
is the standard deviation. When this is convolved with the function of an image this will blur
the image due to the smoothing effect of the Gaussian. This degree of blurring effect is
determined by the value of o. this might seem strange to blur the image but this effect is
discussed further on in the report. So if the laplacian it taken and combined we get this
equation below: 2h(r)=(r202 o4 )e r2 2o2.
Now it is obvious way this function is called the laplacian of a Gaussian. This does not make
it harder to use this new equation 2h(r) as this is same process as with the smoothing
function blur the image one of the strange things that is need to do the image is to blur it. The
reason way the image is blur is due to large amount of folded edges and to only gain the most
dominant edges that are in the image this can be seen in the photo below:
So if we applied edge detecting to this image there would be some folded edges, as edge are
determined by the functions discussed earlier. The shadow that runs through the image; this
would be an edge to the program. By blurring the image, the shadow would be blurred out
and live the more defined edges like that of the building.
The gradient
It is knowing that by averaging pixels over an area tends to blur the detail in an image.
Averaging is the same as integration so it is natural to expect that differentiation will have the

10 | P a g e

opposite effect and thus make the image have more sharpen edges. The most used method of
differentiation in image processing is that of gradient. This function if given by f(x, y) , the
gradient function consists of f which is a coordinates of (x, y) this is then defined as a vector.

[(, )] =

There are is an important point to be made with gradient the first is that of the vector G[f(x,
y)] points in the direction of the maximum rate of increase of the function of f(x, y). The
second is that the magnitude of G[f(x, y)] , this can be denoted this equation :
2
2 0.5
[(, )] = [( ) + ( ) ]

This equations equals the maximum rate of increase of f(x, y) in a unit distance in the
direction of G.

Form the equation above this is the basis for a number of approaches to image differentiation.
For a digital image the derivatives the equation above is approximated by differences.

One typical approximation is given by relation


[(, )] = [{(, ) ( + 1, + 1)}2 + [{( + 1, ) (, + 1)}2 ]0.5
The coding of the program

11 | P a g e

This section will be broken up in to different section as the code is explored and what it does.
The code will be going in the order of how it is set up in the full code. The way this section is
going to look at the code is by going throw each line of code and to show the understanding
of this part. This shows the different method that was used to achieve part of the final code
programme. So the first section is how to display the code using the webcam and by tacking
the image from the data file.
Displaying the image and inserting it in to Matlab
So the first we are going to look at the web cam code
cam = webcam('Logitech')

so this code takes the image from the Logitech or any other camera and loads it in to Matlab
but for the is code we will use this this code:
image=imread(filename);

This code is used to read an image file and in port it in to matlab as a unit8 array and then is
saved as the image function. After this is done the next thing is to remove the cooler from the
image as this is not need to do edge diction this is done but the use of this code
I = rgb2gray(RGB);

This make the RGB image with coaler and turns it in to a grey image. This make it easy to
edge detect as there is no need to define colour, as there are only shades.
The next part is to look at filtering the image this be using the Gaussian filter. The first is
going to be the inbuilt one in matlab. This is so there is a control so that it can be compared to
the program that is in the second code.
B = imgaussfilt(A,sigma)

12 | P a g e

The A is the image that was resaved from the grey-scale this is then passed throw the
Gaussian filter. The sigma is the Standard deviation of the Gaussian distribution, specified as
a scalar or 2-element vector of positive values.
The next part is to look at the Gaussian function that will not use the inbuilt matlab functions.
The code for this is blew and how the thought process was used to make the code work.
The first step is to make the Gaussian mask; this is archived by use the code blow the step
that the code fall is expanded next

ind = -floor(N/2) : floor(N/2);


[X Y] = meshgrid(ind, ind);

This part generates the horizontal and vertical parts of the mask this is done by the code
meshgrid is used to create the grid, the floor function is used to make sure that the grid is
always in the centre of the image, this is assuming that the grid is n x n. The next part is to
create the Gaussian mask this is done

h = exp(-(X.^2 + Y.^2) / (2*sigma*sigma));

sigma calculates the singular values of the frequency response of a dynamic system sys. The
exp is exponential of the equation and the x and y are the coordinates from the previous
code:

h = h / sum(h(:));

The sum code is to Normalize so that total area or sum of all weights to be 1. The next part
will be to see how to implement this to the image so that the filter can be performed on to the
image.

13 | P a g e
I = im2double(I);
I_array = padarray(I, [floor(N/2) floor(N/2)]);
C = im2col(I_array, [N N], 'sliding');
C_filter = sum(bsxfun(@times, C, h), 1);
out = col2im(C_filter, [N N], size(I_pad), 'sliding');

So the first thing is to use the im2double this converts it to a double the next is to put the
image in to a pad array this is use to fine the boundaries of the image then next part is to I'
use the im2col that will take pixel group and turn them into columns. im2col will take each
of these columns and create a matrix where each column represents one pixel group. The next
is to sum all the components up to give us the filter this is then done by using the
bsxfun(@times, - , -, ) function to applies the element-by-element binary operation which is
that of the Array multiply. This then leads to the last line in this code the col2im function this
turns the filtered image back in to the matrix this is so that the image can be displayed as an
image and so the second part can be performed the laplacion.

The laplacian coding


This part would have looked in to the laplacian part of the coding and how this would have
been implemented but due to the time management of this paper the was not time to complete
this part this is folded up in the conclusion of this paper.

Using the code in the practical world and how it was used
In this part of the coding will be looking to what the edge detention could be used for and the
code to implement this this has been done by using the inbuilt function for the edge detection
in matlab. This is so that the coding in this section is not effect bay the coding in the last

14 | P a g e

section the first is to look in to defining the shaped that might appear on to image like that of
circles and squares.
Shapes in matlab
The first is to use the following code:
threshold = graythresh(GRAY);
BW = im2bw(GRAY, threshold);

This takes the grey-scaled image and finds the threshold of the image and create a black and
white shapes this is not grey-scale is only black or white in the image now. This is done to
helping define the shapes that we are looking at the next part is to look at the im2bw put the
black white image in to a binary form this is to make it easier to manipulate. This could to
change the save and change the rotation of the shapes in the image.
Then next step is to find the boundaries of the shape this is done like this:
[B,L]= bwboundaries(___)

This returns a label matrix L where objects and holes are labelled.
The next part is defining the shape, finding the size of the shape. Then the next part is to look
at the using this shapes and measuring how big this shapes are this is done by the code below
this find the non-zeros of the shape and then fines the size of the max and min of the
horizontal and vertical of the shape this then calibrates this by taking the min from the max
this than give the size of the shape
The code below completed the prior actions:
[r1,c1] = find(BW);
spy(BW);
x2 = max(r1);
x1 = min(r1);
X = x2 - x1
y2 = max(c1);
y1 = min(c1);
Y = y2 - y1

15 | P a g e

This code was used to find all of the non-zeros in the binary image, this is then used for the
spy function spy (S) plots the sparsity pattern of any matrix S then the finding the max
and min of the column and rows this give us the tow x and y coordinates to find the size of
the shape in the x and y domains.

Results
This section the code that has been used in the coding part will be used to see if it functions
and if not this will also be compared to the inbuilt function of matlab so see the comparison.
This is to see if the function that have be use in this paper are as effective as those found in
matlab
The first is to see if the webcam works as the university version matlab will not all us to use
the webcam this cannot be seen so for this test an image will be used using the imread
command so the first is to see that the Gaussian filter works.
This is the image that we are going to tray and us the Gaussian filter

Figer(5)

This is the image that was after the inbuilt function was used Iblur = imgaussfilt(I, 2) and as
I can be observed the image is blurred

Figer(6)

Now that there is an image to compare to the Gaussian that I have written I will compare the
results from to the one in the that I have written.

16 | P a g e

Figure(7)

The results from the gradient function is very similar to that of the inbuilt function. The
function is different as the image that I have to created is more blurred thus is need to be
looked at in the further. The next is to look at the code that measures the distance of the
object in the image this is done using the code in the previous section the code was as
followed:
[r1,c1] = find(BW);
spy(BW);
x2 = max(r1);
x1 = min(r1);
X = x2 - x1
y2 = max(c1);
y1 = min(c1);
Y = y2 - y1

This code gave us the results in the figure blow

Figer(8)

figer(9)

17 | P a g e

The figure(8) has the image of the object that is in question and the result of the code used.
The top graph in figure is the objet a black box on a white background this this image also
shows us the box on a graph. The graph shows us the size other box in pixels. The bottom
graph in figure(8) is the box after the box has had grey-scaling and edge detection applied. To
the right is figure(9) this shows us the results from the code above. By using the code answers
and the top image in figure(8) the answer is accurate. This than can be turned into the real
world value by calibrating the size of the image so that a pixel is a certain distance, this than
comes a task of changing the pixel vale in that of meters.

Conclusion
In conclusion this project has not meat it requirement as there has be no edge detection code
been put forward. There has been a significant part of the code done for the laplacian of
Gaussian and the Gaussian filter has been compiled and has shown that function. The smaller
part of the code like that of detection of the shapes has not be completed either but like that of
the laplacian of Gaussian has a large part completed. The other part like that of the measuring
and of webcam and of grey scaling have been completed in this fashion. This then leads me
to further discus the reasons for the no completion of the project in this paper.

The reason for the no completion of this paper is due to that of time restrains. This has come
about in the form of not managing the time I had to complete this paper. Another reason is
lack of knowledge in using the matlab program and the understanding of it workings as well
as not clearly understanding the project outline. So without these failings would be a notable
improvement, if I would undertake if this project would be taken again. The most important
is that of the time management I would allocate more time in to researching the matlab

18 | P a g e

programing and that of the gradient and laplacian techniques, this could also be used to take
additional learning in the use of matlab as well as putting a clearer objective to achieve.

19 | P a g e

References
Gonzales,R.C, Woods,R.E, Eddins,S.L (2004) Digital images processing using matlab,
Gonzales,R.C, Wintz,P (1983) Digital images processing,
http://uk.mathworks.com/support/?s_tid=gn_supp - matlab support website

You might also like