• 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: , , , ,

  • Two years ago I started coding a small program in C++ to simulate gravitational forces between masspoints. After seeing a video of a simulation of matter clustering under gravitation in my astrophysics lecture I decided to continue and improve the code.

    I wanted the simulation to be easily extentable, so I made a class for the objects, which holds their parameters and some I/O-functions, and a class for the world, which contains all objects in a list and the functions to calculate their interactions.

    The algorithm is quite simple. For each calculation step the world goes through all objects and calculates the forces excerted on it by every other object. It then calculates the acceleration of the object and subsequently its new velocity and position.

    For visualisation of the results the coordinates of each object are written to a file after each step. (This part isn’t working correctly yet. There seems to be some problem with the fstream.)
    These coordinates are then read by a 3ds-max script to keyframe coordinates of spheres or alternatively to pointcoordinates of splines.

    I also wrote a similar algorithm in Delphi, which only computes the movement of two masspoints, but directly visualises the result by drawing to lines. The linewidth varies with the absolute value of the z-position and the hue represents the speed at this point.

    A more detailed description of the mathematical background can be found here.

    Download sourcecode

    Tags: , ,

  • Parallel-to-I²C-Adapter


    Just a little circuitboard to interface I²C-chips to the parallel-port.

    I designed the layout so it can fit inside the case of the connector.

    An additional diode to protect LS05 from reverse polarity might be good. (I already ‘converted’ one to smoke 🙁 )

    Eagle5 layout and some simple TurboC++-Code for the adapter can be downloaded here.

    Tags: , , , , ,