Edge Detection algorithm and code

28
EDGE DETECTION Presented by: Vaddi Manikanta B212053 ETC

Transcript of Edge Detection algorithm and code

Page 1: Edge Detection algorithm and code

EDGE DETECTIONPresented by: Vaddi Manikanta B212053 ETC

Page 2: Edge Detection algorithm and code

INTRODUCTIONEdges are significant local

changes of intensity in an image.

Edge Detection is the process of identifying and locating sharp discontinuities in an image.

Abrupt change in pixel intensity characterize boundary of an object and usually edges occur on the boundary of two regions.

Tulips image

Edges of the Tulips image

Page 3: Edge Detection algorithm and code

Tulips Image Part of the image Edge of the part of the image

Matrix generated by the part of the image

Page 4: Edge Detection algorithm and code

CAUSES OF INTENSITY CHANGEGeometric eventsDiscontinuity in depth and surface colour and textureNon-geometric eventsReflection of lightIlluminationshadows

Edge formation due to discontinuity of surface

Reflectance Illumination Shadow

Page 5: Edge Detection algorithm and code

APPLICATIONS

Enhancement of noisy images like satellite images, x-rays, medical images like cat scans.Text detection.Traffic management.Mapping of roads.Video surveillance.

Page 6: Edge Detection algorithm and code

DIFFERENT TYPES OF EDGES OR INTENSITY CHANGES

Step edge: The image intensity abruptly changes from one value on one side of the discontinuity to a different value on the opposite side.

Page 7: Edge Detection algorithm and code

Ramp edge: A step edge where the intensity change is not instantaneous but occur over a finite distance.

Ridge edge: The image intensity abruptly changes value but then returns to the starting value within some short distance (i.e., usually generated by lines).

Page 8: Edge Detection algorithm and code

Roof edge: A ridge edge where the intensity change is not instantaneous but occur over a finite distance (i.e., usually generated by the intersection of two surfaces).

Page 9: Edge Detection algorithm and code

MAIN STEPS IN EDGE DETECTION

Smoothing: Suppress as much noise as possible, without destroying true edges.

Enhancement: Apply differentiation to enhance the quality of edges (i.e., sharpening).

Thresholding: Determine which edge pixels should be discarded as noise and which should be retained (i.e., threshold edge magnitude).

Localization: Determine the exact edge location. Edge thinning and linking are usually required in this step.

Page 10: Edge Detection algorithm and code

EDGE DETECTION USING DERIVATIVE (GRADIENT)

The first derivate of an image can be computed using the gradient

(or)f

Page 11: Edge Detection algorithm and code

GRADIENT REPRESENTATIONThe gradient is a vector which has magnitude and

direction.

or

Magnitude: indicates edge strength.Direction: indicates edge direction.

| | | |f fx y

(approximation)

Page 12: Edge Detection algorithm and code

EDGE DETECTION STEPS USING GRADIENT

(i.e., sqrt is costly!)

Page 13: Edge Detection algorithm and code

GENERAL APPROXIMATIONConsider the arrangement of pixels about the pixel [i, j]:

The partial derivatives , can be computed by:

The constant c implies the emphasis given to pixels closer to the centre of the mask.

3 x 3 neighborhood:

Page 14: Edge Detection algorithm and code

SOBEL OPERATOR

3×3 convolution mask.Setting c = 2, we get the Sobel operator:

Page 15: Edge Detection algorithm and code

EDGE DETECTOR USING SOBEL OPERATOR IN C LANGUAGE #include <stdio.h>#include <stdlib.h>#include <float.h>#include "mypgm.h"

void sobel_filtering( ) /* Spatial filtering of image data */ /* Sobel filter (horizontal differentiation */ /* Input: image1[y][x] ---- Outout: image2[y][x] */{ /* Definition of Sobel filter in horizontal direction */ int weight[3][3] = { { -1, 0, 1 },

{ -2, 0, 2 }, { -1, 0, 1 } };

double pixel_value; double min, max; int x, y, i, j; /* Loop variable */

Page 16: Edge Detection algorithm and code

/* Maximum values calculation after filtering*/ printf("Now, filtering of input image is performed\n\n"); min = DBL_MAX; max = -DBL_MAX; for (y = 1; y < y_size1 - 1; y++) { for (x = 1; x < x_size1 - 1; x++) { pixel_value = 0.0; for (j = -1; j <= 1; j++) {

for (i = -1; i <= 1; i++) { pixel_value += weight[j + 1][i + 1] * image1[y + j][x + i]; }

} if (pixel_value < min) min = pixel_value; if (pixel_value > max) max = pixel_value; } }

Page 17: Edge Detection algorithm and code

if ((int)(max - min) == 0) { printf("Nothing exists!!!\n\n"); exit(1); }

/* Initialization of image2[y][x] */ x_size2 = x_size1; y_size2 = y_size1; for (y = 0; y < y_size2; y++) { for (x = 0; x < x_size2; x++) { image2[y][x] = 0; } }

Page 18: Edge Detection algorithm and code

/* Generation of image2 after linear transformtion */ for (y = 1; y < y_size1 - 1; y++) { for (x = 1; x < x_size1 - 1; x++) { pixel_value = 0.0; for (j = -1; j <= 1; j++) {

for (i = -1; i <= 1; i++) { pixel_value += weight[j + 1][i + 1] * image1[y + j][x + i]; }

} pixel_value = MAX_BRIGHTNESS * (pixel_value - min) / (max - min); image2[y][x] = (unsigned char)pixel_value; } }}

main( ){ load_image_data( ); /* Input of image1 */ sobel_filtering( ); /* Sobel filter is applied to image1 */ save_image_data( ); /* Output of image2 */ return 0;}

Page 19: Edge Detection algorithm and code

SOBEL EDGE DETECTOR

Page 20: Edge Detection algorithm and code

PREWITT OPERATOR3×3 convolution mask.Setting c = 1, we get the Prewitt operator:

Page 21: Edge Detection algorithm and code

PREWITT EDGE DETECTOR

Page 22: Edge Detection algorithm and code

GENERAL EXAMPLE

Idxd

IdydI

Page 23: Edge Detection algorithm and code

22d dI Idx dy

100Threshold

I

Page 24: Edge Detection algorithm and code

PRACTICAL ISSUESChoice of threshold

Gradient Magnitude

Low Threshold High Threshold

Page 25: Edge Detection algorithm and code

Edge thinning and linking.

Page 26: Edge Detection algorithm and code

CONCLUSIONReduces unnecessary information in the image while

preserving the structure of the image.Extract important features of an image like corners, lines

and curves.Recognize objects, boundaries, segmentation.Part of computer vision and recognition.Sobel and prewitt operators are similar.

Page 27: Edge Detection algorithm and code

REFERENCESMachine Vision – Ramesh Jain, Rangachar Kasturi, Brian

G Schunck, McGraw-Hill, 1995A Computational Approach to Edge Detection – John

Canny, IEEE, 1986CS485/685 Computer Vision – Dr. George Bebis

Page 28: Edge Detection algorithm and code

THANK YOU!