0
$\begingroup$

Let's say I have a $2 \times 2$ pixel of grayscale picture, where there is one edge such that the left pixel contains a value, 30, and the right pixels contain a value 0 (in red below). And for edge detection I have zero-padded the input image and then used the Sobel vertical filter to find out the vertical edges and apply ReLU to the output. The output is a $2 \times 2$ matrix with all pixel values $0$. So that should mean there is no edge in the picture whereas in actual case it has one. Where am I going wrong?

Enter image description here

$\endgroup$
1
$\begingroup$

I assume that you would like to use convolution with padding with the same size of output matrix as this picture. You messed up calculations with convolution with "full padding". If we imagine these two matrices as windows that slide on each other, you can see that the filter is symmetrically inverted. I used a little bit different filter to show you in a better way how it works (I changed the last row to [-3, 0 3]).

Assuming these matrices:

Enter image description here

You should add to your picture matrix two rows and columns of zeros:

Enter image description here

Then you can start matrix multiplication, but notice that the filter is symmetrically inverted. The result shown as matrix $4 \times 4$ is the convolution with "full padding". The $2 \times 2$ matrix in the middle is a result of convolution with the "same padding", that you requested.

Enter image description here

Next step:

Enter image description here

Some iterations later:

Enter image description here

And later:

Enter image description here

And finally:

Enter image description here

For convolution with the same size, the result will be the small $2 \times 2$ matrix in the middle.

Enter image description here

After using the ReLU function, the result will be exactly the same.

So with using of your filter, the result would look like [[0,90], [0,90]].

$\endgroup$
  • $\begingroup$ Totally appreciate your detailed explanation. But it would really help if you can educate me further on the below 2 questions. 1. Why did you choose the different filter? I mean is it completely random or there is a process to arrive to the correct filter. 2. Since the pixel value (0 -> 30 -> 0) changes in in same proportion in the input image so in the convolved image if i use your filter then why are we getting different values (90, 150)? I guess the ixels in the convolved image gives the rate of change of pixel value in the original picture right? Shouldn't theybe same? $\endgroup$ – Abhranil Mukhopadhyay Jan 5 at 13:04
  • $\begingroup$ Ad 1. Your filter is OK. I decided to change values in last row to make it more visible, that matrix is "flipped" in both axis. That can be confusing. Ad 2. That's the metter of values in my filter and those "3s" in last row. Pure math. With using of your filter, the result is (90,90). $\endgroup$ – ketzul Jan 6 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.