1
votes

I am learning about the Convolution Matrix, and I understand how they work, but I don't understand how to know before hand what the output of a Matrix will look like. For example lets say I want to add a blur to an image, I could guess 10,000+ different combinations of numbers before I get the correct one.

I do know though that this formula will give me a blur effect, but I have no idea why.

float[] sharpen = new float[] {
     1/9f, 1/9f, 1/9f,
     1/9f, 1/9f, 1/9f,
     1/9f, 1/9f, 1/9f
};

Can anyone either explain to me how this works or point me to some article, that explains this? I would like to know before hand what a possible output of the matrix will be without guessing.

Basically I would like to know why do we put that number in the filed, and why not some other number?

3
In general your matrix should add up to either 1.0 or 0.0 depending on the effect you want.Mark Ransom

3 Answers

4
votes

This link that explains how the convolution matrix works with a simple example.

The reason the matrix you have in your question blurs the image is because each pixel becomes an average of all its surrounding pixels. In other words, the pixel that's in the center of the action area has its new value equal to the following formula:

new_value = (1/9)(top-left-neighbor)    + (1/9)(top-neighbor)    + (1/9)(top-right-neighbor) +
            (1/9)(left-neighbor)        + (1/9)(self)            + (1/9)(right-neighbor)     +
            (1/9)(bottom-left-neighbor) + (1/9)(bottom-neighbor) + (1/9)(bottom-right-neighbor)

The new value is 1/9th of 9 pixels (including the original pixel value) which turns out to be an "average" value for the 3x3 square operated on by the matrix. This "average" effect creates the blur that you see after applying the matrix.

Picking values for a convolution matrix all depends on what effect you want to achieve. Keep in mind that the matrix is applied to the original image and the new pixel value is copied over to the destination image. This means that the new values don't factor into the application of the matrix on neighboring pixels...it's only the original values that get fed into the matrix.

0
votes

The convolution operation is basically a filter: think of it like a tool that walks over your image and performs stuff locally.

You can start by reading this article, and if you want to dig deeper search Wikipedia for convolution - a bit of real analysis and signal processing theory knowledge is welcome, but if you are interested you can come up with that.