Laplace and Sobel
This section of the tutorial will introduce two more interesting image filtering functions to you namely, Laplace and Sobel. I hope that you have went through the
theory of how the Laplacian and Sobel are taken for an image. You are always welcome to do some extra reading from other websites/textbooks about the operations.
theory of how the Laplacian and Sobel are taken for an image. You are always welcome to do some extra reading from other websites/textbooks about the operations.
#include <opencv2\opencv.hpp> using namespace cv; int main() { int laplacesize = 1,sobel_dx = 1, sobel_dy = 1, sobelsize = 1; int lsizemax = 3, smaxsize = 3, max_dx = 2, max_dy = 2; const char *lapwindow = "Laplace image", *sobelwindow = "Sobel image"; const char *laptrack = "Laplace size" , *sobels = "Sobel Size"; const char *sobeldy = "y order",*sobeldx = "x order"; IplImage *im = cvLoadImage("F:\image.jpg"); IplImage *imlaplace = cvCreateImage(cvGetSize(im),8,3), *imsobel = cvCreateImage(cvGetSize(im),8,3); cvNamedWindow(lapwindow); cvNamedWindow(sobelwindow,3); cvCreateTrackbar(laptrack, lapwindow, &laplacesize, lsizemax, NULL); cvCreateTrackbar(sobels, sobelwindow, &sobelsize, smaxsize, NULL); cvCreateTrackbar(sobeldx, sobelwindow, &sobel_dx, max_dx, NULL); cvCreateTrackbar(sobeldy, sobelwindow, &sobel_dy, max_dy, NULL); while(cvWaitKey(10) != 27) { cvLaplace(im, imlaplace, 2*laplacesize+1); cvSobel(im, imsobel, sobel_dx, sobel_dy, 2*sobelsize+1); cvShowImage("Original Image", im); cvShowImage(lapwindow, imlaplace); cvShowImage(sobelwindow, imsobel); } } |
#include <opencv2\opencv.hpp> using namespace cv; int main() { int laplacesize = 3,sobel_dx = 1, sobel_dy = 1, sobelsize = 3; int lsizemax = 3, smaxsize = 3, max_dx = 2, max_dy = 2; const char *lapwindow = "Laplace image", *sobelwindow = "Sobel image"; const char *laptrack = "Laplace size" , *sobels = "Sobel Size"; const char *sobeldy = "y order",*sobeldx = "x order"; Mat im = imread("F:\image.jpg"), imlaplace, imsobel; namedWindow(lapwindow); namedWindow(sobelwindow); createTrackbar(laptrack, lapwindow, &laplacesize, lsizemax, NULL); createTrackbar(sobels, sobelwindow, &sobelsize, smaxsize, NULL); createTrackbar(sobeldx, sobelwindow, &sobel_dx, max_dx, NULL); createTrackbar(sobeldy, sobelwindow, &sobel_dy, max_dy, NULL); while(waitKey(10) != 27) { Laplacian(im, imlaplace, CV_8U, 2*laplacesize+1); Sobel(im, imsobel, CV_8U, sobel_dx, sobel_dy, 2*sobelsize+1); imshow("Original Image", im); imshow(lapwindow, imlaplace); imshow(sobelwindow, imsobel); } } |
Explanation
cvLaplace(im, imlaplace, 2*laplacesize+1); cvLaplace(const CvArr* src, CvArr* dst, int apertureSize=3) is the fucnction used to find the laplacian of an image.
cvSobel(im, imsobel, sobel_dx, sobel_dy, 2*sobelsize+1); cvSobel(const CvArr* src, CvArr* dst, int xorder, int yorder, int apertureSize=3)
is the function used to apply sobel operation on an image.
|
Laplacian(im, imlaplace, CV_8U, 2*laplacesize+1); Laplacian(const Mat& src, Mat& dst, int ddepth, int ksize=1) is the function in C++ which is used too find the laplacian of an image.
Sobel(im, imsobel, CV_8U, sobel_dx, sobel_dy, 2*sobelsize+1); Sobel(const Mat& src, Mat& dst, int ddepth, int xorder, int yorder, int ksize=3)is the function used to apply sobel operation on an image.
|
I really like it when people come together and share opinions.
Great site, keep it up!