Suzan Cioc
Suzan Cioc

Reputation: 30127

What are Canny thresolds?

Is it possible to make Canny to ignore short edges or to ignore low gradient edges? In my case I have card lying on wood and see numerous edges of wood structure after canny

enter image description here

What two thresholds in canny functions are for?

Upvotes: 1

Views: 5105

Answers (2)

user1693593
user1693593

Reputation:

Large intensity gradients are more likely to correspond to edges than small intensity gradients. It is in most cases impossible to specify a threshold at which a given intensity gradient switches from corresponding to an edge into not doing so. Therefore Canny uses thresholding with hysteresis.

Thresholding with hysteresis requires two thresholds – high and low. Making the assumption that important edges should be along continuous curves in the image allows us to follow a faint section of a given line and to discard a few noisy pixels that do not constitute a line but have produced large gradients. Therefore we begin by applying a high threshold. This marks out the edges we can be fairly sure are genuine. Starting from these, using the directional information derived earlier, edges can be traced through the image. While tracing an edge, we apply the lower threshold, allowing us to trace faint sections of edges as long as we find a starting point.

Once this process is complete we have a binary image where each pixel is marked as either an edge pixel or a non-edge pixel. From complementary output from the edge tracing step, the binary edge map obtained in this way can also be treated as a set of edge curves, which after further processing can be represented as polygons in the image domain.

See also:

Thresholds: the use of two thresholds with hysteresis allows more flexibility than in a single-threshold approach, but general problems of thresholding approaches still apply. A threshold set too high can miss important information. On the other hand, a threshold set too low will falsely identify irrelevant information (such as noise) as important. It is difficult to give a generic threshold that works well on all images. No tried and tested approach to this problem yet exists.

In your case you can probably increase the threshold value a bit to see if it reduces the short lines a bit more.

Source:
https://en.wikipedia.org/wiki/Canny_edge_detector#Tracing_edges_through_the_image_and_hysteresis_thresholding

Update:

For this image I would perhaps pre-process it by applying lower contrast to it. This can help reduce the details in the background of the image a bit before you run it through the blurring and line detector.

Upvotes: 4

Bull
Bull

Reputation: 11951

Using GaussianBlur() before Canny will help remove much of the unwanted detail. And maybe increase the low threshhold as @Ken suggested

Upvotes: 2

Related Questions