When coding the gravitational simulation I found some old code from 2003 that was supposed to perform edge detection in images. Back then I did not have enough knowlegde in C++ to get it working right.

Therefore I started with a completely new program.

When a BMP-image is loaded, first its header is read into to structs, containing exactly the right set of variables, so that the information is easily readable.

When needed, the pixel information is read into a dynamic twodimensional array of structs containing three unsigned 8bit integers. For this purpose I wrote a little template since C++ does not natively support dynamic memory allocation of multidimensional arrays.

Then a number of algorithms can be performed on this array.

Some of them are easy operations on single pixels, like inversion of colors, converting to greyscale or subtracting one picture from another.

But the really interesting filters involve matrix convolutions. That means you take a sliding window the size of your matrix (preferrably of odd dimensions) and calculate the value for the central pixel by multiplying the surrounding pixels by the respective entries of the matrix.

This way a lot of effects can be achieved.

One of the more simple ones is blurring the picture. You just take the average of the pixels around the central pixel and put that value into the pixel. A better blurring can be done by weighting the entries with a gaussian function.

The reverse effect is possible, too. A sharpening matrix subtracts the sourrounding pixels from the center.

I implemented some matrices in the code but added a function that can dynamically read an arbitray matrix and perform a convolution on the image, so that new filters can be tested quickly.

The program accepts as many arguments as you like and executes them in the order of entering.

The main goal of the program is to detect edges in images.

There are a lot of ways to filter out edges in images, i.e. calculating the second derivative with a laplacian or estimating the gradients with gaussian and derivative-of-gaussian (DoG) convolutions.

I am currently working on the non-maximum-suppression-algorithm which should preprocess the images for the edgedetector. The SUSAN-algorithm is already implemented and the Canny-Algorithm will follow shortly.

The sourcecode can be found here (a compiled executable is included).

## Leave a Reply