Digital image processing using PLT Scheme and VIGRA = VIGRAPLT
Description of the interface
PLT Scheme (or DrScheme) at version >=4.0 makes it quite easy to add so-called "Foreign-Code", that is program code that is not written with Scheme itself. That is why we have chosen this interface (called Foreign-Funktion-Interface: FFI) for the VIGRAPLT. With the FFI you can add the algorithms of C-conform dynamic libraries (e.g. under Windows: DLLs, under MacOSX: dylibs) to your Scheme program at runtime and use them right out-of-the-box. Obviously we connect Scheme to the VIGRA_C library as the VIGRA itself does not offer a dynamic C-library containing all algorithms. We also hide the low-level calls from the user in that way, that the user can only see the tiny Scheme functions and does not have to care about conversion to pointers or memory allocation.
Datastructures
The bindings to the C-Interface should be efficient, which means that we wanted to have as less overhead as possible. An image for example should just be once in memory and not two or tree times including "expensive” conversions to fit to the interface. That is why we describe the new structures, which were introduced by th VigraPLT into PLT Scheme.
Representation of images
In this extension, the representation of an image is given by a list of its bands (color channels). Each band is represented as a built-in "cvector" of element type "float", because it allows a simple FFI handling without memory overhead. Unfortunately this cvector is only defined for the one-dimensional case, so we have extended it first to n dimensions (which can be found in the file "vigraplt.carray.ss" ).
This extension is important, because we want to define an image as a two-dimensional datatype that allows to store a float value for each pixel. In practice of image processing, the n-dimensional "carray" is unimportant, as there are helper functions for images, that directly support this special type of two-dimensional datastructure.
Representation von matrices
Right now, we need the representation von matrices only for a single function of the VigraPLT benötigt: affinetransformimage, which needs a transformation matrix to transform the given image. In general, matrices have nearly the same representation as images, with the only difference, that the value type of a matrix is a floating point number of double precision. Considering the system memory of our computers, we can afford this, as matrices are mostly "smaller" than images. The functions and function names are nearly the same than for images.
The following table lists all functions, that are offered by the VIGRAPLT:
![]() |
||||
vigraplt.impex |
vigraplt.imgproc |
vigraplt.filters |
vigraplt.segmentation |
vigraplt.morphology |
loadimage saveimage |
resizeimage-band resizeimage rotateimage-band rotateimage affinewarpimage-band affinewarpimage reflectimage-band reflectimage fouriertransform-band fouriertransform |
convolveimage-band convolveimage separableconvolveimage-band separableconvolveimage gsmooth-band gsmooth gaussiangradient-band gaussiangradient ggradient-band ggradient laplacianofgaussian-band laplacianofgaussian gsharpening-band gsharpening sharpening-band sharpening nonlineardiffusion-band nonlineardiffusion distancetransform-band distancetransform |
labelimage-band labelimage watersheds-band watersheds cannyedgeimage-band cannyedgeimage differenceofexponentialedgeimage-band differenceofexponentialedgeimage regionimagetocrackedgeimage-band regionimagetocrackedgeimage |
erodeimage-band erodeimage dilateimage-band dilateimage openingimage-band = (dilateimage-band (erodeimage-band band)) openingimage = (dilateimage (erodeimage img)) closingimage-band = (erodeimage-band (dilateimage-band band)) closingimage = (erodeimage (dilateimage img)) |
Beside these bound functions, there are some more funktions that will make functional digital image processing a lot easier:
vigraplt.helpers |
||
Image |
Array |
Matrix |
Construction:make-image Accessors: image-data, image-width, image-height, image-ref, image-set! Conversion: copy-image,image->list, list->image Functional support: image-map, image-map!, image-reduce, image-for-each-index |
Construction:make-array Accessors: array-data, array-width, array-height, array-ref, array-set! Conversion: copy-array,array->list, list->array Functional support: array-map, array-map!, array-reduce, array-for-each-index |
Construction: make-matrix Accessors: matrix-data, matrix-rows, matrix-cols, matrix-ref, matrix-set! Conversion: copy-matrix,matrix->list, list->matrix Functions: matrix-mult |
Examples
Embedding of the VIGRAPLT into PLT Scheme( VIGRAPLT has to be located inside the "collects" folder)
> (require vigraplt/vigraplt)
Afterwards you may want to load an image (here: "blox.gif"):
> (define img (loadimage (build-path vigraplt-path "blox.gif")))
Smoothing the image with a Gaussian filter of sigma=3 save the result to img2:
> (define img2 (gsmooth img 3.0))
Convert the smoothed image from image domain to frequency space using the FFT:
> (define img3 (fouriertransform img2))
Using the image helper functions, it is very easy to write your own algorithms, e.g a thresholder:
> (define (threshold image t) (image-map (lambda (x) (if (> x t) 1.0 0.0)) image))
Or another case: Cutting an image by a given mask:
> (define (mask_image image mask) (image-map (lambda (value mask) (if (> mask 0.0) value 0.0)) image mask))
Download & Installation
Aktuelle Version 0.5.0
The current release (Version 0.5.0) can be downloaded here. It consists of the VIGRAPLT Component (in folder vigraplt) and of the necessary VIGRA_C files (in subfolder vigra_c) (see above for more informations).This release does not conatain the VIGRA itself.
Installation instructions for MacOS X:
Creating a dynamic library (libvigra_c.dylib)
Just make the Makefile which is loacated at the subfolder "vigra_c". After successful "make", "make install" copies the binaries into the right folder . As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Installation instructions for Linux:
Creating a dynamic library (vigra_c.so)
- Edit the Makefile at folder "vigraplt/vigra_c" to find the vigra library.
- make linux
- make install
- As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Installation instructions for Windows:
You may either want to download the precompiled binaries for Win32 here and copy the included "vigraimpex.dll" into the Windows System-directory (e.g. Windows\System32) or
Creating a dynamic library (vigra_c.dll)
You'll find a Visual Studio Projectfile in the subfolder "vigra_c\win32-msvc2005". Please make sure to set the right paths to the VIGRA (Lib & Include!) in the projects options and then compile the projectto create the DLL file. After the compilation, you should find a file called "vigra_c.dll" inside the Release folder. Please copy this DLL into the "vigraplt" folder. As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Ältere Versionen
Known bugs in the current version of VIGRAPLT:
Unfortunately a small bug found its way to some helper module of the VIGRAPLT. This bug will of course be fixed by the next release. If you want, you can fix this bug on your own, which is quite easy: Just change the function list->image inside the file "vigraplt.helpers.ss"like this:
50: ; list -> image conversion 51: (define (list->image lst) 52: (list->carray lst _float))
The same bug also affects the list to matrix conversion, that can be found and fixed in the same file:
156: ; list -> matrix conversion 157: (define (list->matrix lst) 158: (list->carray lst _double))
In Opposite to the reference manual, the function labelimage uses an 8-Pixel-Neighborhood to find connected componentsdurch, und benutzt somit nicht wie im Handbuch beschrieben den 4er-Zusammenhang!
The older release (version 0.1.0) can be downloaded here. It consists of the VIGRAPLT Component (in folder vigraplt) and of the necessary VIGRA_C files (in subfolder vigra_c) (see above for more informations).This release does not contain the VIGRA itself.
Installation instructions for MacOS X:
Creating a dynamic library (vigra_c.dylib)
Just make the Makefile which is loacate at the subfolder "vigra_c". After successful make, there should be a file called "vigra_c.dylib" at the VIGRAPLT directory. As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Installation instructions for Linux:
Creating a dynamic library (vigra_c.so)
There is currently no straightforward way for the compilation of a linux shared object. On the other hand, you should easily be able to make the necessary changes:
- Change the Makefile at folder "vigraplt/vigra_c" to create a C-compatible (-fPIC e.g.) shared object file at folder vigraplt.
- Change the vigraplt.cl file to search for the vigra_c.so file if the platform is Linux. Therefore look at line 2-4 .
- As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Installation instructions for Windows:
You may either want to download the precompiled binaries for Win32 here or
Creating a dynamic library (vigra_c.dll)
You'll find a Visual Studio Projectfile in the subfolder "vigra_c\win32-msvc2005". Please make sure to set the right paths to the VIGRA (Lib & Include!) in the projects options and then compile the projectto create the DLL file. After the compilation, you should find a file called "vigra_c.dll" inside the Release folder. Please copy this DLL into the "vigraplt" folder. As a last step you need to link the vigraplt folder into the PLT Scheme "collects" directory. This ensures, that the "require" command of PLT Scheme works correctly.
Future Milestones:
- Embedding of further VIGRA functions