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.
1 |
1 |
- Sobel
- Canny
- Prewitt
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.
Is there any way to do it in Matlab??
_________________________________________________________________________________
Example
Image = imread('yourimage.jpg');
edg = edge(Image,method,threshold);
imshow(edg);
_________________________________________________________________________________
_________________________________________________________________________________
Canny Operator
edg = edge(Image,method,threshold);
imshow(edg);
_________________________________________________________________________________
_________________________________________________________________________________
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:
#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
- 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.
____________________________________________________________________________
Example
Example
#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;
}
_________________________________________________________________________________
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
No comments:
Post a Comment
I FEEL AWESOME WHEN YOU COMMENT.