Convolution on Matrices

373 Views Asked by At

I am trying to underrstand the convultion operation applied on an image in this book, page 332, formula 9.5, and here is the equation:

$(K * I)(i,j) = \sum_{m}\sum_{n}I(i-m,j-n)K(m,n) $

I can not understand what do m and n stand for here? I assumed they are the sizes of the kernel and the image respectively, then if we subtract m or n from either i or j will end up with a negative number!!

Can anyone help the formula this

1

There are 1 best solutions below

2
On

They indices $m$ and $n$ do indeed range over the dimensions of the kernel, and you're correct that as written it's unclear what is meant when the indices go beyond the bounds of the image. In practice, there are a few ways it can be handled. One is to not define $(K*I)(i,j)$ if computing it would require indices outside the dimensions of the image. This is essentially ignoring some pixels around the edge of your image. You could also extend the image by using the nearest border pixel (so that, for example, $I(-1,-1)$ is taken to be $I(0,0)$). You could also wrap the border pixels if that makes sense in the given context.

In the book you provided, on page 334 it looks like they take the first approach (at least in that example) and just don't define the convolution where it require pixels from beyond the the bounds of your image. This is why the input is 3x4 pixels but the output is only 2x3.