Some experiments with simple image processing algorithms
Ruby Vim script
Switch branches/tags
Nothing to show
Clone or download
AndrewRadev Add Gemfile.lock
At this point, it's not really a gem, it's just an experimental project,
so pinning down its gem versions seems reasonable.
Latest commit 1bba227 Sep 23, 2012
Failed to load latest commit information.
examples Add some examples Mar 11, 2012
lib Logarithm transform May 1, 2012
spec Median adaptive threshold Jan 30, 2012
README.markdown Some more information Mar 18, 2012


This is a small repository of some of my experiments with image processing. The algorithms are nothing special and can probably be found in Wikipedia as pseudocode, but it was very interesting for me to implement them and combine them to solve a specific problem for a university assignment.


Histogram normalization

Basically, whenever the levels of gray in an image are clumped close together, it makes sense to spread them throughout the [0, 255] range. This often takes care of excessive brightness or darkness.



Two kinds of blurring are implemented, a simple mean blur and a gaussian blur. The gaussian blur uses a fixed 3x3 kernel.

Info on mean, median and gaussian blurring.

Mean blur with a radius of 3 (5x5 matrix)
Gaussian blur

Edge detection

Two filters for edge detection are implemented, Laplacian and Sobel. The results they give are quite different and can probably be used with varying success on different occasions.

Info on LoG, and on Sobel. The code for the Sobel operator was taken almost as-is from Sau Sheong Chang's blog post about it, so check that out as well.

Laplacian over gaussian


There's not much to explain about the simple thresholding by a given value. A more interesting type of thresholding is the iterative one. Basically, it takes an initial value and tries to threshold the image by that. The average intensity of the foreground and background pixels is then used to perform another threshold, and so on until it converges on a "best" value.

In cases with varying lighting, adaptive thresholding is better. The most popular method for that seems to be Otsu's, but for now, I've implemented a simpler one. Each pixel is thresholded by the mean or by the median of the surrounding pixels.

The Floyd-Steinberg algorithm for error propagation is used as an alternative to the standard thresholding by a fixed value. I've yet to experiment with it and expect to make it a bit more useful.

Info on thresholding in general and on adaptive thresholding. Info on iterative (or automatic) thresholding can be found on wikipedia.

Adaptive thresholding