Understanding Filters

Hi, I hope readers are in great health. I came across a filter question in a quiz. In course 1, we learned that if there are 1s on the left and -1s on the right, it is a vertical edge filter (with 0s in the center). Similarly, if there are 1s on the top and -1s on the bottom, it is a horizontal edge filter (again, with 0s in the center).

For readers who are not aware of the meaning of 1 and -1 in this context:

  • 1 represents light/bright pixel values.
  • -1 represents dark pixel values.

So my question is: how can I decide the type of filter based on the values in it? Any articles, YouTube links, or explanations would be appreciated. Thank you!

Hello,
Check out this wikipedia article. I think it would help. It presents several types of filters, and links to more articles with more explanations. Good luck.

1 Like

Hi Mushtaq,

Note the rows in the filter:

  • The positive values (1, 3) are concentrated in the upper left corner of the kernel.
  • The negative values (-1, -3) are concentrated in the bottom right corner of the kernel.

This pattern suggests horizontal intensity changes as the transition from positive to negative is vertical. When applied to an image, this kernel will highlight regions where there is a horizontal gradient (e.g. bright pixels at the top and dark pixels at the bottom). Review Week 1 of the Convolutional Neural Networks course, especially the ConvNet Basics videos, which explain kernels in detail with visual examples.

YouTube tutorials:

  • 3Blue1Brown has intuitive visual explanations of convolutional layers and filters.
  • Search for videos like “Edge Detection in Image Processing” or “Convolutional Kernels Explained” for more clarity.

Articles:

  • “Intuitively Understanding Convolutions for Deep Learning” by Towards Data Science provides a good foundation.

Hope this helps!

3 Likes

In addition to the useful links to YouTube and Wikipedia, note that Prof Ng covered this in the lectures. If you missed that, it might be worth watching the relevant lecture again: the title is Edge Detection Example and it’s the second lecture in Week 1. He specifically uses edge detection as his example to give the intuition for how convolutional filters can be useful.

1 Like

I initially selected ‘horizontal edge’ in the quiz, but it was marked incorrect. Then, I chose ‘vertical edge,’ but that was also incorrect. I realized it would be better to learn the concept rather than guessing the answer. Thank you for the video link, I’ll definitely watch it!

1 Like

I did, sir. I always take notes while watching lectures, but this one was a bit overwhelming and hard to grasp. I wasn’t really understanding it

The other thing to be careful about is that the quiz questions are not necessarily exactly the same every time you take the quiz. I would say that filter you show is a vertical edge detector. If you chose that answer and it was marked wrong, I’ll bet that the filter in the second case was different than what you showed above.

1 Like

@Mushi I’d also say the filters, as they are presented in the course are kind of simple (though it is only an ‘intro’-- we step up fast to convolutions), but I’d check out Floyd-Steinberg dithering.

Same concept, smaller scale, but you might ‘suddenly get what we are doing’.

1 Like

The way I think about it, it’s not the specific numerical values in the static filter that reveal its properties. Instead, it’s the symmetry (or lack thereof). In the quiz example you provide, there is a symmetry around the horizontal axis…impact of the filter is the same above and below its center. However, it is not symmetrical around the vertical axis…values from combining the filter with the input signal are pushed in opposite directions. So in this case, any differences between the left and right will be enhanced. In other words, a vertical edge.

Notice that this is consistent with your text description of what you were taught.

The example has both 1 and -1 (and 3 and -3) both above and below the center, it’s symmetric, so horizontal edge is not correct.

It’s not the numeric values 1 and -1 themselves that are the clue, it is the way the weights are distributed throughout the filter. Hope this helps

3 Likes

I read about it on Wikipedia and got a bit of an idea, but it’s still unclear. I’ll watch a video on it and see what I can learn.

It helped me sir, thankss man. love you bro for taking out the time and guiding me, now its really clear to me, I was so dumb looking at specific numbers rather than looking at the pattern, your explanation went into my head rather than over my head :smile:
have a good day brother.

2 Likes

Yeah, no, @ai_curious is pretty good :wink:

1 Like

I’ve been supporting the Deep Learning forums since 2018. This might be the best feedback I have ever received. It’s certainly what I aspire to with every reply. Thanks for letting me know this one hit the mark. :pray:

4 Likes