2023.10.25
Today's agenda
1. edge detection & sobel filter
2. kenny edge detection
3. hough transform algorithm
Edge in an image called to
1. A part that pixel value has extremly changed
2. Normally border between object and background or object and another object
3. edge detection is essential procedure for object detection and recognization
Most of image has noise. For wanted edge detection, noise filter is needed. using Gaussian blur is mosly used.
For edge detection, pixel's get value from has extremly changed part to 1st
differential point from x point or y point
But only x differential or y dirrerential can not detect all of edged in an image.(like a column space in image). and 1st differential can not detect edge for decrease differential value.
Because above problem. get gradient of x and y diffential vector for detect exact edge detection in image
void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT);
parameters
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
void sobel_impl();
void sobel_func();
int main()
{
Mat src = imread("lenna.bmp", IMREAD_GRAYSCALE);
if (src.empty()) {
cerr << "Image load failed!" << endl;
return;
}
Mat dx, dy;
Sobel(src, dx, CV_32FC1, 1, 0);
Sobel(src, dy, CV_32FC1, 0, 1);
Mat mag;
magnitude(dx, dy, mag);
mag.convertTo(mag, CV_8UC1);
Mat edge = mag > 150;
imshow("src", src);
imshow("mag", mag);
imshow("edge", edge);
waitKey();
destroyAllWindows();
}
Method of kenny edge detection
1. gaussian filtering
2. get gradiant(sobel mask)
3. non-maximum suppression
4. Hysteresis edge tracking
void Canny(InputArray image, OutputArray edges, double threshold1, double threshole2, int apertureSize = 3, bool L2gradient = false);
parameters
void HoughLines(InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn = 0, double stn = 0, double min_theta = 0, double max_theta = CV_PI);
parameters
void HoughLinesP(InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength = 0, double maxLineGap = 0);
parameters