• I completely recoded the Image Manipulation program. It is now better structured and easier to use. Additionally I implemented the Canny Edge Detector Algorithm and some more filters. 8-bit BMP’s are still not supported, so that would be the next step.

    Binary edge image output from canny algorithm

    Binary edge image output from canny algorithm

    To test the edge detector, I used the image from the Wikipedia article on the topic, as the desired result was known for that image.

    Complete C++ code can be downloaded here (executable included).

    Executing the program without parameters displays the help.

    To perform edge detection on an image, use the following parameter sequence:

    image <input.bmp> <output.bmp> -g -f 0.8 -e -n 80 -w 80 50

    This command first converts the image to greyscale (-g), then applys gaussian blur with a standard deviation of 0.8 (-f 0.8). After that, Sobel filters for X and Y direction are convoluted with the image, which gives an edge image. Those edges are now thinned by Non-Maximum-Suppression (-n 80),  which only leaves one-pixel wide edges, which are above the given threshold. Finally the edge tracer (-w 80 50) deletes pixels not belonging to an edge, by appling hysteresis thresholding.

    Tags: , , , , , , , ,

  • 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.

    Gradient Estimation

    Gradient Estimation

    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).

    Tags: , , , ,