# Edge detecting filter besides the basic horizontal and vertical one

Hello community,
During the course, I heard that Dr. Andrew Ng mentioned the filter/kernel using to detect the horizontal, vertical edges and the 45, 70,etc degree edge. As I imagine, with the 45 degree line, we can detect it with the filter size of 3x3 or 5x5, but the unusual line like 70 degree line and 80 degree line must be detected by the large scale of filter, isn’t it ? because the small filter like 3x3 and 5x5 cannot describe the pattern of the unusual line correctly. Am I understand this concept correctly?
And if I want to detect those usual line, is there any way to design the filter ?

1 Like

Sounds to me like you’re thinking about this correctly. And already anticipating why static, predefined filters are so limiting. Even if you could figure out how to represent an 80 degree line, what about an 83 degree line? Or the shape of an eye? Or what a field looks like when it needs to be irrigated? Deep learning gets you out of the business of hand crafting filters and lets the filter weights become data driven. Your convolution engine becomes profoundly more flexible and powerful.

It is better for you to think about two areas. One is traditional computer vision, and the other is neural network computing.

In the traditional computer vision area, there are some famous filters. I think the most famous one is a “Sobel” filter which is a discrete differentiation filter. There is no concept of 80 degree, 70 degree, etc. The idea is to use vertical and horizontal Sobel filter to calculate “gradients” of an image, then merge two outputs (horizontal and vertical) to create a 3D gradient map. Then, edges can be outlined. It’s a simple 3x3 filter, but, it works pretty good for the edge detection.
But it’s just edge detections, and does not detect several features from different aspects.

A deep neural network does have filters, but those are trainable weights. Those are not fixed type filters like “Sobel” filter. So, we do not know what will be the final shape of the filter after an optimization. But, in the case of supervised learning, we have a ground truth. Tasks can be regression, classification, or any. It’s not just an edge detection, but learns several features in images.

This is one of papers that Andrew introduced in his lecture. Visualizing and Understanding Convolutional Networks
It shows which layer is focusing on which feature with filter shapes. It’s an interesting paper. The filter size for the layer 1 is 7x7, relatively large one. Then, use 5x5, then, 3x3, and so on.

Hope this helps.

I’m curious. I thought the shapes of the filters were fixed; just the values were dynamic. Can you elaborate on what determines the shape of the filter? Thanks

This “shape” does not mean “dimension”. It means " the form of the outer edges or surfaces of something; an example of something that has a particular form" – from the Oxford dictionary.
It should cover like “diagonal shape”, “horizontal shape”, and so on.

Sorry for making you confused.

Thanks for the clarification. I guess my confusion stems from occurrences in TensorFlow doc where shape and dimension are more or less synonymous. The narrative at

for example. Pretty sure if you ask TensorFlow for the shape of a 3x3 Sobel filter, it won’t depend on the values. Cheers