How to Detect Edges (in Image processing)


Edge detection is an image processing technique that is used for finding the boundaries of objects within images. The points at which image brightness changes sharply are declared as edges.


Edge detection
1



Edge detection
1
The three most common methods for edge detection are
  • Sobel 
  • Canny 
  • Prewitt 


Sobel Operator
Sobel operator perform a 2-D spatial gradient measurement on an image.
                   Mathematically,
The operator uses two 3×3 kernels which are convolved with the original image. Note that different masks are used for vertical and horizontal edges.
Sobel Edge Detection





Is there any way to do it in Matlab??

Yes you can use "edge()" function in matlab for sobol edge detection. You can also use this function for canny and prewitt operator.
_________________________________________________________________________________
Example
Image = imread('yourimage.jpg');
edg = edge(Image,method,threshold);
imshow(edg);
_________________________________________________________________________________
_________________________________________________________________________________


Canny Operator
Canny Operator uses a multi-stage algorithm to detect a wide range of edges in images. The Canny edge detection algorithm can be broken down into 5 steps:
  • Apply Gaussian filter to smooth the image in order to remove the noise 
  • Next step is to find the intensity gradients of the image 
  • Then apply non-maximum suppression to get rid of spurious response to edge detection 
  • Apply double threshold to determine potential edges 
  • Finalize the detection of edges by suppressing all the other edges that are weak and not connected to strong edges.

    Canny Edge Detection

How can i do it in OpenCV??

____________________________________________________________________________
Example
#include<stdio.h>
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture(0); // capture video
if(!capture.isOpened())
{printf("error to initialize camera");  return 1; }
Mat cap_img,gray_img; // define image matrices
 Mat detected_edges;
while(1)
{
capture >> cap_img;  // capture frame from cam
cvtColor(cap_img, gray_img, CV_BGR2GRAY); // convert to Grayscale
Canny( gray_img, detected_edges, 20, 60, 3 );      // Apply canny edges
                imshow("video", cap_img);                     // show RGB image
imshow("Edges", detected_edges);               // show Detected edges

                if(waitKey(10) >= 0) break;                  // press escape to exit program
}
return 0;
}
_________________________________________________________________________________

Prewitt Operator
The Prewitt operator is based on the convolution of image with a small, separable, and integer valued filter in horizontal and vertical directions. This operator also require less computations. The mask used for this purpose is as follow


Prewitt Edge Detection

.

No comments:

Post a Comment

I FEEL AWESOME WHEN YOU COMMENT.