ZeroRay – Ray Tracer, Computer Vision Toolkit

A scene rendered by ZeroRay

A scene rendered by ZeroRay illustrating reflection and refraction. The glass orbs both reflect and transmit light through them.

ZeroRay began its life as a ray tracer. Building a ray tracer from scratch was one of the large projects for a graduate level computer science course I took called Image Computation. I ended up using ZeroRay in a lot of other projects and it has evolved into a ray tracer/computer vision (CV) toolkit with a suite of deep applications that are both interesting, and illustrate how to use ZeroRay.

I have released ZeroRay as open source software, under the BSD license. The BSD License is pretty much the most liberal open source license. The basic jist is that you can use the code for anything you want, be it open or closed source, commercial or non-commercial. All you have to do is give the author credit for using their library. You can visit the ZeroRay project page at sourceforge. At the time of this writing, I haven’t prepared any convenient downloadable packages so you will have to check the code out of the svn repository. To do so click Develop on the project page and follow the instructions there.

If you’re wondering, “What’s a Ray Tracer?” check out my previous article What is Ray Tracing?

Back to what exactly ZeroRay is. ZeroRay is a software library (or more precisely a set of software libraries). That means it is a set of tools that are used by programmers to create applications. A simple application could be one that, when executed, draws a pre-set picture and saves it to an image file. A more complex application could be a program that allows you to set up a 3D scene by dragging objects into it a low quality rendering of the scene and then invokes the ZeroRay ray tracer to generate a high quality version of the image. As a bit of an aside: ray tracing is a way to generate very high quality computer graphics, however it is significantly more computationally intensive than the techniques used in real-time renderers, like the sort that are used in video games. To make the ZeroRay ray tracer widely useful to computer artists (who generally are not programmers), it would need an application similar to the second example. But ZeroRay is more than a ray tracer.

More Than a Ray Tracer

There are a number of high-quality, mature ray tracers in the world. Why build another? Well, as I mentioned, I started it as a project for a class, but what ZeroRay really offers is its combination of 3D rendering and a computer vision (CV) toolkit. Both libraries are a part of ZeroRay and use the same set of foundational classes, vectors, matrices, images, etc. The image class is full-featured and implements a number of useful algorithms as well as simple tools like annotating or marking images as is often needed to test CV algorithms. The CV toolkit also implements convolution/correlation providing both brute force algorithms and Fast Fourier Transform (FFT) based algorithms built with FFTW.

ZeroRay is not nearly as fully-featured as OpenCV, the current go-to CV toolkit, but ZeroRay provides a well-designed, modern, object-oriented foundation for CV. It contains all the building blocks that a student of CV would have to spend several months writing before they started their work.

ZeroRay Opalescent Render

A ZeroRay Rendering of glass spheres lit by various coloured light sources.

The Image class is especially useful. It is implemented in a speed-optimized but still relatively straightforward manner. Users can load an image and begin working with pixel data directly without having to read a chapter in the manual first (as one might to begin working with OpenCV images). ZeroRay reads and saves in png format. In memory, the Image class (zr::Image) can represent many different types of pixel data, greyscale, RGB, RGBA, all in discrete (4 bits per channel) or floating point (32 or 64 bits per channel) format. Floating point images are important because many CV algorithms and transformations need to be performed with much more numerical precision than images are usually stored in. Without this extra precision iterated calculations would result in very large rounding errors as results are rounded off at each step of the way.

Applicatons Module

The applications module contains a set of example programs that use either the zeroray (ray tracing) or zrvision (CV) libraries. However, these aren’t just simple example programs, each one is a project I completed for my CV coursework. They’re pretty cool and show what can be done with ZeroRay.

zrExample – This is the ray tracer demo. It has a handful of scenes (defined in code) that it can render either to the screen or to a file, at arbitrarily large resolutions. This is the place to look to learn how to set up and render a scene with the ray tracer. It is easy to modify one of the pre-defined scenes, re-compile and render the new scene.

AeroQuest – The task was to take a shaked, hand-held, video of a plane landing and stabilise the picture so that the plane stays in the center by using correlation. The end result is a command line executable that takes in a set of images, a template bounding box in the first frame, and outputs a set of images with the template held in the center. Or at least it tries to. The technique fails if the object in the template changes size or shape dramatically (this is an expected shortcoming).

WineAndCheese – A classifying algorithm than gives a set of images scores on a “Grapes vs. Cheese” score. For a given set of pictures where some are grapes and some are cheese it gives all the grape images a higher “grape score” than the cheese. It works by using a circular hough transform to count the number of circles in an image. The more circles, the higher the grape score. Not expected to work generally on all arbitrary images of grapes or cheese.

VidendoAedificare – See my previous article Videndo Aedificare.

-Jess

Tags: , , , , , , ,

Leave a Reply