Edge detection is a fundamental tool in image processing and computer vision, particularly in the areas of feature detection and feature extraction, which aim at identifying points in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuities in 1D signals is known as step detection
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "cvaux.h"
int _tmain(int argc, _TCHAR* argv[])
{
IplImage * image=cvLoadImage("C:/Users/PENUMARTHY/Desktop/a.jpg",1);
IplImage * gray= cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
IplImage * sobel= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * laplace= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * cannay=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage * corner=cvCreateImage(cvGetSize(image),IPL_DEPTH_32F,1);
cvCvtColor(image,gray,CV_BGR2GRAY);
cvPreCornerDetect( gray, corner, 7 );
cvCanny (gray,cannay,150,100, 3 );
cvSobel( gray,sobel,1,1,7 );
cvLaplace( gray, laplace, 7 );
cvNamedWindow("cannay",1);
cvShowImage("cannay",cannay);
cvNamedWindow("laplace",1);
cvShowImage("laplace",laplace);
cvNamedWindow("sobel",1);
cvShowImage("sobel",sobel);
cvNamedWindow("prewit",1);
cvShowImage("prewit",corner);
cvNamedWindow("gray",1);
cvShowImage("gray",gray);
cvNamedWindow("show",1);
cvShowImage("show",image);
cvWaitKey(0);
}
following are some of the edge detection techniques usually followed by the programmers for edge detection
1) Canny edge detector
2) Sobel edge detector
3) Laplace edge detector
4) Prewitt edge detector
5) Robert edge detector
The Canny edge detection operator was developed by John F. Canny in 1986 and uses a multi-stage algorithm to detect a wide range of edges in images. Most importantly, Canny also produced a computational theory of edge detection explaining why the technique works.
The Sobel operator is used in image processing, particularly within edge detection algorithms. 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 Sobel operator is either the corresponding gradient vector or the norm of this vector. The Sobel operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical direction and is therefore relatively inexpensive in terms of computations. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image.
The Prewitt operator is used in image processing, particularly within edge detection algorithms. 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 Prewitt operator is either the corresponding gradient vector or the norm of this vector. The Prewitt operator is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical direction and is therefore relatively inexpensive in terms of computations. On the other hand, the gradient approximation which it produces is relatively crude, in particular for high frequency variations in the image.
following is the code for implementing the edge detection techniques in opencv
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "cvaux.h"
int _tmain(int argc, _TCHAR* argv[])
{
IplImage * image=cvLoadImage("C:/Users/PENUMARTHY/Desktop/a.jpg",1);
IplImage * gray= cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
IplImage * sobel= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * laplace= cvCreateImage(cvGetSize(image), IPL_DEPTH_16S, 1);
IplImage * cannay=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);
IplImage * corner=cvCreateImage(cvGetSize(image),IPL_DEPTH_32F,1);
cvCvtColor(image,gray,CV_BGR2GRAY);
cvPreCornerDetect( gray, corner, 7 );
cvCanny (gray,cannay,150,100, 3 );
cvSobel( gray,sobel,1,1,7 );
cvLaplace( gray, laplace, 7 );
cvNamedWindow("cannay",1);
cvShowImage("cannay",cannay);
cvNamedWindow("laplace",1);
cvShowImage("laplace",laplace);
cvNamedWindow("sobel",1);
cvShowImage("sobel",sobel);
cvNamedWindow("prewit",1);
cvShowImage("prewit",corner);
cvNamedWindow("gray",1);
cvShowImage("gray",gray);
cvNamedWindow("show",1);
cvShowImage("show",image);
cvWaitKey(0);
}
output:-














