159 points · by icc97 · 8y ago · 44 comments
This was my only tangible contribution to the Gimp, some twenty years ago. IIRC it was modelled after a similar feature in Paint Shop Pro, and it was easy enough an exercise for an aspiring programmer. Or so I thought: others have now spent much more time maintaining it than I spent writing it.
In hindsight it seems like a bizarre idea to have a feature whose GUI requires filling in 25 numbers. But perhaps it has use as an educational tool.
In development version of the Gimp, the entire plugin has effectively been rewritten. Good riddance!
I've been trying to get a handle on what convolutions really are. Which ever description I read is usually so abstract as to be meaningless. But your plugin is a beautiful way to play with them an understand them in a fundamental way.
N.B. I came across it because of Chris Olah's blog post [0].
[0]: http://colah.github.io/posts/2014-07-Understanding-Convoluti...
There is no better way, if you need to specify an arbitrary matrix, than to ask for 25 numbers to be input.
https://i.stack.imgur.com/YDusp.png
don't worry about continuous convolutions
e.g. a= [1,2,3] and b=[4,5,6].
p_1 = 1 + 2x + 3x^2 + ...
p_2 = 4 + 5x + 6x^2 + ...
p_1 * p_2 = 4 + 13x + 28x^2 + ...
Hence the convolution of a and b is [4, 13, 28, ...].
Here's the full answer:
octave:1> conv([1,2,3], [4,5,6])
ans =
4 13 28 27 18
The intuition behind convolution to me for an image is uniform blurring. If you have a square shaped eraser, and you use it to blur a pencil sketch, the sketch will appear blocky and square shaped. Or perhaps a better analogy is painting: your wall will appear different depending on whether you use a paintbrush or a roller.Not certain that's the correct intuition but it makes sense to me haha.
Another way of seeing why the symmetry emerges is that mirroring the image over an axis shouldn't change the edges you observe (this is the case for the edge detection). So, mirroring the underlying image shouldn't change the operation we wish to apply to detect edges.
http://setosa.io/ev/image-kernels/
Highly recommended!
conv(x(t), y(t))(q) = integral (x(t)·y(q-t) dt)
where x(t), y(t) are functions. Or, with sums and x, y are vectors
conv(x, y)(q) = sum(over i + j = q+1) of (x(i)·y(j))
whereas the definition of the autocorrelation is "simpler"
ac(x(t), y(t))(q) = int(x(t)·y(t-q))
In other words, it replaces y(t) with y(-t) (i.e., the autocorrelation of x(t) and y(t) is the same as the convolution of x(t) and y(-t)). A similar transformation happens for the discrete case.
Turns out, in the context of learning, these are equivalent since it just corresponds to a relabelling of the indices (which is an invertible linear transformation). In fact, even more strongly, independent of the order of the method (so long as it is >0th order!), this will cause no change in the descent direction or objective value, unlike arbitrary invertible linear transformations (for which this is only true of ≥2nd order methods).
https://www.youtube.com/watch?v=MQm6ZP1F6ms
https://www.youtube.com/watch?v=C3EEy8adxvc
If you look at the kernel differences, for symmetric kernels they are the same, for non-symmetric they are flipped.
As for dividing, that's what the Divisor option is for. To quote the article:
"The result of previous calculation will be divided by this divisor. You will hardly use 1, which lets result unchanged, and 9 or 25 according to matrix size, which gives the average of pixel values."
https://imagej.net/Rolling_Ball_Background_Subtraction
It took me a while to realise that this is just a cousin of convolution: in a convolution, as you sweep the kernel over the image, combine pairs of pixels and kernel elements with multiplication, then summarise the results with addition, whereas with a rolling ball, you combine the pixels and kernel elements with subtraction, and summarise the results with the maximum. The kernel used is the 'ball', but there's no real reason it has to be based on a sphere in any way.
I wonder what other image processing operators could be built in that framework?
the setosa interactive says convolution is "a technique for determining the most important portions of an image"
the hubel and wiesel experiment showed "there is a topographical map in the visual cortex that represents the visual field, where nearby cells process information from nearby visual fields. Moreover, their work determined that neurons in the visual cortex are arranged in a precise architecture. Cells with similar functions are organized into columns, tiny computational machines that relay information to a higher region of the brain, where a visual image is formed"
I'm interested in David Marr's work, about to order Vision: A Computational Investigation into the Human Representation and Processing of Visual Information, his level of analysis approach is interesting. I think he did work on edge detection, which must of been involved some kind of convolution/filter
This setosa interactive is great, and actually references the gimp documentation
http://setosa.io/ev/image-kernels/
An image kernel is a small matrix used to apply effects like the ones you might find in Photoshop or Gimp, such as blurring, sharpening, outlining or embossing. They're also used in machine learning for 'feature extraction', a technique for determining the most important portions of an image. In this context the process is referred to more generally as "convolution"
https://knowingneurons.com/2014/10/29/hubel-and-wiesel-the-n...
The classic experiments by Hubel and Wiesel are fundamental to our understanding of how neurons along the visual pathway extract increasingly complex information from the pattern of light cast on the retina to construct an image. For one, they showed that there is a topographical map in the visual cortex that represents the visual field, where nearby cells process information from nearby visual fields. Moreover, their work determined that neurons in the visual cortex are arranged in a precise architecture. Cells with similar functions are organized into columns, tiny computational machines that relay information to a higher region of the brain, where a visual image is formed.
https://ps.is.tuebingen.mpg.de/research_fields/inverse-graph...
Computer vision as analysis by synthesis has a long tradition and remains central to a wide class of generative methods. In this top-down approach, vision is formulated as the search for parameters of a model that is rendered to produce an image (or features of an image), which is then compared with image pixels (or features). The model can take many forms of varying realism but, when the model and rendering process are designed to produce realistic images, this process is often called inverse graphics. In a sense, the approach tries to reverse-engineer the physical process that produced an image of the world.
IMO, convolution in CNNs would be better denoted as correlation. In CNNs the feature maps are convolved (correlated), eg swept over the image and multiple at each spot with the results being accumulated, in order to find where in the image these filters fit. The output produces a map of how strongly each filter (there are usually multiple in a convolution layer, that is the third dimension of the layer), fits with the image. These become the weights passed onto the next layers.
As an electrical engineer by training, who used convolution all the time, I didn't understand how the two were related, especially because of the third dimension.
I read this https://adeshpande3.github.io/A-Beginner%27s-Guide-To-Unders... and that lead me to how I understand it today.
The project needs all the help it can get.
These matrices are slow. Many kernels used in practice are separable https://blogs.mathworks.com/steve/2006/11/28/separable-convo... and therefore much faster to compute than a generic convolution matrix.
Also the UI is hard to use. 25 edit boxes is a lot.