Canny Edge Detection, Thesis of Digital Image Processing

How to implement canny edge detection using 'C'

Typology: Thesis

2015/2016

Uploaded on 02/29/2016

shubhamdhage
shubhamdhage 🇮🇳

1 document

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
IMPLEMENTATION OF CANNY EDGE
DETECTOR USING C
Submitted in partial fulfilment of the requirements for the degree of
Bachelor of Technology
In
Electronics & Telecommunication Engineering
By
Shubham M. Dhage
(Reg. No. 2011BEC118)
Prasad V. Kale
(Reg. No. 2011BEC021)
Under the Guidance of
Dr. R. R. Manthalkar
Shri Guru Gobind Singhji Institute of Engineering &
Technology, Nanded
2014-15
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Canny Edge Detection and more Thesis Digital Image Processing in PDF only on Docsity!

IMPLEMENTATION OF CANNY EDGE

DETECTOR USING C

Submitted in partial fulfilment of the requirements for the degree of

Bachelor of Technology

In

Electronics & Telecommunication Engineering

By

Shubham M. Dhage

(Reg. No. 2011BEC118)

Prasad V. Kale

(Reg. No. 2011BEC021)

Under the Guidance of

Dr. R. R. Manthalkar

Shri Guru Gobind Singhji Institute of Engineering &

Technology, Nanded

CERTIFICATE

This is to certify that this project report entitled “IMPLEMENTATION OF

CANNY EDGE DETECTOR USING C” submitted to SGGS Institute of

Engineering & Technology, Nanded is a bonafide record of work done by

1. Shubham M. Dhage

2. Prasad V. kale

Under my supervision in the year 2014-

Dr. R. R. Manthalkar Dr. S. S. Gajre

Project Guide H.O.D.

EXTC EXTC Department

Date :

Place : Nanded

ABSTRACT

In this era of digital computers , digital image processing is the most significant subfield of electronics & computer engineering. as compaired to the other natural signals, there is no other signal which can carry as much information with same amount of data as an image signal or in other way can say-

“One picture is worth more than ten thousand words.” Today, there is almost no field in technology that is not get impacted in some way by digital image processing. Though human perception is limited to visible spectrum of Electromagnetic waves but there are artificial imaging machines which reveals the entire EM spectrum from gamma to radio waves, which makes it possible to have applications of image processing in almost all areas of technology. Which motivates the students to the field of digital image processing.

Loking towards the history digital image processing, though there is a lots of devlopment have happened in the field of edge detection, as beginner in this field I am starting with problem of edge detection. Edges characterize boundaries and are therefore considered for prime importance in image processing. Edge detection filters out useless data, noise and frequencies while preserving the important structural properties in an image. Since edge detection is in the forefront of image processing for object detection, it is crucial to have a good understanding of edge detection methods. In this project the comparative analysis of various Image Edge Detection methods is presented. The evidence for the best detector type is judged by studying the edge maps relative to each other through statistical evaluation. Upon this evaluation, an edge detection method can be employed to characterize edges to represent the image for further analysis and implementation. It has been shown that the Canny‟s edge detection algorithm performs better than all these operators under almost all scenarios.

INDEX

CONTAINTS PAGE NO.

ABSTRACT IV

1. INTRODUCTION

1.1 WHY IMAGE PROCESSING WITH C 1

1.2 BASICS OF IMAGE 1

1.3 ARITHAMATIC OPERATIONS 2

1.4 BASIC RELATIONSHIPS BETWEEN PIXELS 3

2. EDGE DTECTION

2.1 INTRODUCTION 4

2.2 FUNDAMENTALS 4

2.3 BASIC EDGE DETECTION 5

2.4 THE CANNY EDGE DETECTOR 6

3. BMP FILE FORMAT

3.1 BITMAP HEADER FILE 11

3.2 BITMAP HEADER INFO 12

4 FILE HANDELING IN C

4.1 WHAT IS FILE HANDELING

4.2 WHAT ARE TYPES OF FILE 14

4.3 FUNCTIONS FOR FILE HANDELING 15

5 APPLICATIONS 16

CONCLUSION 17

REFERENCES 18

Fig 1.1) 2D representation of image

Mathematically image can be viewed as M × N matrix as shown below

1.3 ARITHMATIC OPERATION ON IMAGE

We have seen in last section Image can viewed as two dimensional matrix .But in arithmatic operation images are treated as arrays and operations are performed as fallows, let f(x, y) ,and g(x, y) are two images of same size then we can have third image w(x, y) as

W(x, y) = f(x, y) + g(x, y);

W(x, y) = f(x, y) - g(x, y);

W(x, y) = f(x, y) *g(x, y);

Note that while performing arithamatic operations two images must be of same size and they are treated as arrays not matrix unless otherwise staed.

1.4 BASIC RELATIONSHIPS BETWEEN PIXELS

Neighbors of pixel :-

 For a Pixel ‘p’ with co-ordinates (x,y),set of pixels having co- ordinates (x+1,y),(x-1,y),(x,y+1),(x,y-1) is called “4-neighbours of p”,& is denoted by N 4 (p). Pixels on boundary lack some of the 4- neighbours.  The set of pixels having co- ordinates (x+1,y+1),(x-1,y-1),(x-1,y+1),(x+1,y-1) is called “diagonal neighbors of p” ,& is denoted by N 8 (p).  These neighbors, together, are termed to be “8-neighbours of p”, & are denoted by N 8 (p).

Fig 2.4:-Concept of Neighbor-hood

2) Second derivative

Using first derivative we can write it as

Which is centered about x+1 ,shifting it to x

Properties of these derivatives^1 are directly discussed below: Magnitude of response at the point is much stonger for the second order derivative than for first order. Because the second order derivative much more aggressive than a first order derivative in enhancing sharp changes in intensity. first order derivative generally produces thicker edges in an image. second order derivative have a stronger response to fine details such as thin lines ,isolated points. Second order derivative produces double edge response at ramp and step transitions. From previous discussion it is reasonable that second derivative can be used efficiently for detection of points in an image. For two dimensional image function we can use laplacian operator as second derivative denoted by

Which can be written in discrete form as

Which can be implemented by 3×3 mask as shown below

Fig. Mask for implementation of laplacian of image.

2.3 BASIC EDGE DETECTION

Presence of noise in image affects the ideal edge detection. In practice detected edges contains both the true and false edges due to noise. In comparison first and second derivative, second derivative is get more affected by noise. Here we will develop directional edge detection on the basis of gradient operator given by

[ ] [ ]

Magnitude of vector is given as M(x, y) = mag( ) = (^) √. The direction of gradient vector is given by

( ) [ ] (^).

The direction of edge at any point (x, y) is orthogonal to the direction (^ ), i.e. (^ )^ will give edge normal at point (x, y). Now we can calculate similarly as in laplacian

( ) ( )

( ) ( )

Different masks to implement above equation is shown in figure.

Fig. Roberts operator

Fig. prewitt opertor

Fig. sobel operator

( ) [ ].

As M(x, y) is the image is generated by first derivative, as discussed in section 2.2 edges will contain thick wide ridges around local maxima.

2.4.3 Non Maxima Suppression

In this step we will suppress the thick wide ridges around the local maxima. We do non-maxima suppression generally in 3×3 region, in which we can define only four direction: horizontal, +45^0 , vertical, -- 450 .which gives rise to need of quantization of angle image. Which we can do as shown in figure. Now we will develop short procedure for non-maxima suppression as

  1. Find the direction that is closest to (^ )
  2. If the value of M(x, y) is less than at least one of it‟s two neighbors along the founded direction, let g1(x, y)=0(suppression), otherwise g2(x, y)=M(x, y).

2.4.4 Double thresholding

Now our next target is reduce false edge points. Canny‟s algorithm uses double thrsholding which needs two thresholds: low threshold Tl and high threshold Th. Canny suggested that the ratio of the high to low threshold ratio should be either between 2:1 to 3:1 .now we apply double thresholding to g image by creating another two images as Gh( x, y) = g1(x, y ) >= Th. Gl(x, y) = g1(x, y) >= Tl. Gl(x, y) = Gl(x, y) - Gh(x, y).

Now non zero pixels in Gh(x, y) and G(x, y) can vieved as strong edge pixels and weak edge pixels respectively.

2.4.5 Connectivity Analysis

Now Gh(x, y) contains strong edge pixels which may have gaps. To connect them we use foolowing procedure. a. Locate the next unvisited edge pixel ,p, in Gh(x, y). b. Mark as valid edge pixels all the weak pixels in Gl(x, y) that are connected to p using say , 8- connectivity. c. If all nonzero pixels in Gh(x, y) have been visited go to step d otherwise return step a. d. Set to zero all pixels in Gl(x, y) which are not marked as Valid edge pixels. At the end of this procedure the of this procedure, the final output by the Canny‟s algorithm is formed by adding imeges Gh(x, y) and Gl(x, y). Comparison of images obtained at different stages is shown on next page.

a) b)

CHAPTER 3 : BMP file format

The BMP file format, sometimes called bitmap or DIB file format (for device-independent bitmap ), is an image file format used to store bitmap digital images, especially on Microsoft Windows and OS/ operating systems. In uncompressed BMP files, and many other bitmap file formats, image pixels are stored with a color depth of 1, 4, 8, 16, 24, or 32 bits per pixel (BPP). Images of 8 bits and fewer can be either grayscale or indexed color. Uncompressed bitmap files (such as BMP) are typically much larger than compressed (with any of various methods) image file formats for the same image. The BMP format for image can be divided as follows,

3.1 Bitmap Header File :

This block of bytes is at the start of the file and is used to identify the file. A typical application reads this block first to ensure that the file is actually a BMP file and that it is not damaged. The first two bytes of the BMP file format are the character 'B' then the character 'M' in 1-byte ascii encoding. All of the integer values are stored in little-endian format (i.e. least-significant byte first).

3.2 Bitmap Header Info :

This block of bytes tells the application detailed information about the image, which will be used to display the image on the screen. All of them contain a dword field, specifying their size, so that an application can easily determine which header is used in the image. The reason that there are different headers is that Microsoft extended the DIB format several times. The new extended headers can be used with some GDI functions instead of the older ones, providing more functionality. Since the GDI supports a function for loading bitmap files, typical Windows applications use that functionality. One consequence of this is that for such applications, the BMP formats that they support match the formats supported by the Windows version being run. See the table below for more information.

CHAPTER 4 : FILE HANDLING IN C

4.1What is file handling?

 Memory is volatile and its contents would be lost once the program is terminated. At such times it becomes necessary to store a large amount of data in a manner that can be later retrieved and displayed either in part or in whole. This medium is usually a „file‟ on the disk.  A file is a place on the disk where a group of related data is stored.  File Handling means carrying out distinct operations on the file so as to have interaction with data inside it. It involves following basic operations:  Naming a file.  Opening a file.  Readind data from file.  Writing data into file.  Closing file.

4.2What are the types of files?

 Basic generally encountered types of files are:-Text files & Binary files.  A text file contains only textual information like alphabets, digits, special characters, symbols.  Actually, ASCII codes of these characters are stored in text file.  A binary file is merely a collection of bytes. The example may be a music data or picture stored in graphic file.  If on opening a file if it can be made out what is displayed, then it is a text file otherwise it is a binary file.  Handling of newlines is different for text & binary files.  In text files, character with ASCII value 26 is inserted after last character,Read function would return EOF if this character gets read.There is no such provision of EOF in Binary mode.

4.3 FUNCTIONS USED FOR FILE HANDLING:

 Basic functions used in file handling:

  1. fopen()-used for opening a file. Syntax:-fp=fopen(“filename”,”mode”);
  2. fclose()-used for closing a file. Syntax:- fclose(“filename”,”mode”);
  3. fgetc()-used for getting a character from a file. Syntax:- c=fgetc(filepointer);
  4. fputc()-used for getting a character from a file. Syntax:- fputc(filepointer,c);

 Efficient methods of reading & writing blocks og data:

  1. fread()-reading a block of data of given size at time. Syntax:-fread(&data,size of single data element,total number of elements,file pionter);
  2. fread()-reading a block of data of given size at time. Syntax:-fread(&data,size of single data element,total number of elements,file pionter);

 Functions for traversals in the file:-

  1. fseek()-to move pointer to desired location. Syntax:-fseek(file pointer,lengrth of traversal in bytes,position macro) Position macros are:-

SEEK_SET:-Takes the pointer to start of file. SEEK_CUR:-Takes the pointer to current position. SEEK_END:- Takes the poimter to end of file.