0% found this document useful (0 votes)
26 views

Quantum Physics Gasiorowicz: (Image Edges Threshold1 Threshold2 Aperturesize L2Gradient

The document describes the Canny edge detection algorithm and its implementation in OpenCV. The Canny algorithm includes these main steps: 1) Filtering noise using Gaussian filtering, 2) Finding intensity gradients, 3) Non-maximum suppression to thin edges, 4) Hysteresis thresholding to determine edges. The code sample implements Canny edge detection in OpenCV. It loads an image, converts it to grayscale, applies Canny with adjustable thresholds to detect edges, and displays the output.

Uploaded by

klps6516
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Quantum Physics Gasiorowicz: (Image Edges Threshold1 Threshold2 Aperturesize L2Gradient

The document describes the Canny edge detection algorithm and its implementation in OpenCV. The Canny algorithm includes these main steps: 1) Filtering noise using Gaussian filtering, 2) Finding intensity gradients, 3) Non-maximum suppression to thin edges, 4) Hysteresis thresholding to determine edges. The code sample implements Canny edge detection in OpenCV. It loads an image, converts it to grayscale, applies Canny with adjustable thresholds to detect edges, and displays the output.

Uploaded by

klps6516
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Quantum Physics Gasiorowicz

void Canny(InputArray image, OutputArray edges, double threshold1,


double threshold2, int apertureSize=3, bool L2gradient=false )
Low error rate: Meaning a good detection of only existent edges.
Good localization: The distance between edge pixels detected and
real edge pixels have to be minimized.
Minimal response: Only one detector response per edge.

1. Filter out any noise. The Gaussian filter is used for this
purpose.
2. Find the intensity gradient of the image.
3. Non-maximum suppression is applied. This removes pixels
that are not considered to be part of an edge. Hence,only thin
lines (candidate edges) will remain.
4. Hysteresis: The final step. Canny does use two thresholds
(upper and lower):
(a) If a pixel gradient is higher than the upper threshold, the pixel is
accepted as an edge
(b) If a pixel gradient value is below the lower threshold, then it is
rejected.
(c) If the pixel gradient is between the two thresholds, then it will be
accepted only if it is connected to a pixel that is above the upper
threshold.

1.

#define _GLIBCXX_USE_CXX11_ABI 0

2.

#include <iostream>

3.

#include <opencv2/core/core.hpp>

4.

#include <opencv2/imgproc/imgproc.hpp>

5.

#include <opencv2/highgui/highgui.hpp>

6.

using namespace cv;

7.

using namespace std;

8.
9.

int edgeThresh = 1;

10. int lowThreshold;


11. int const max_lowThreshold = 100;
12. int ratio = 3;

13. int kernel_size = 3;


14. Mat img,dst,gray;
15. Mat edgeout;
16. void edge(int,void*);
17.
18.
19.
20. int main(int argc, char *argv[])
21. {
22. ///read image
23. img = imread("002.jpg", 1);
24. cvtColor( img, gray,CV_BGR2GRAY );
25. /// Create a matrix of the same type and size as src (for dst)
26. dst.create( img.size(), img.type() );
27.
28.
29. namedWindow( "New Image", 0 );
30. createTrackbar( "Min Threshold:", "New Image", &lowThreshold,
max_lowThreshold, edge );
31. waitKey(0);
32. imwrite("result.bmp", dst);
33. return 0;
34. }
35.
36. void edge(int,void*){
37. /// Reduce noise with a kernel 3x3
38. blur( gray, edgeout, Size(3,3) );
39. /// Canny detector
40. Canny( edgeout, edgeout, lowThreshold, lowThreshold*ratio, kernel_size );
41. /// Using Canny's output as a mask, we display our result
42. dst = Scalar::all(0);
43. img.copyTo( dst, edgeout);

44. imshow( "New Image", dst );


45.
46. }
47.
48.
49.
50.

apertureSize aperture size for the Sobel() operator.


sobel():Calculates the first, second, third, or mixed image derivatives
using an extended Sobel operator.

blur( gray, edgeout, Size(3,3) );

C++: void blur(InputArray src, OutputArray dst, Size ksize,


Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT )

img.copyTo(dst, edgeout);

C++: void Mat::copyTo(OutputArray m, InputArray mask) const

You might also like