Monthly Archive for October, 2006

Closing in Flash

Working with images in Flash leads to some simple problems. First of all you have the general performance issues and then no possibilities of working with binary images and fast morphological filters. This makes it really hard to approach good results. For example: The background subtraction experiment works with a basic scene subtraction technique.

Some time ago I have done some “research” (German article) and created all programs in C++. The scene subtraction was very good and I had no holes in the extracted objects. Just because I was able use a three-dimensional color space and also grayscale and binary immages together.

What makes a binary image so important? Of course most color information will be lost. What you still have is the shape of an object. You can apply a lot of filters to a binary image and they are very fast since you only got {0;1} instead of {0;…;255} values per channel. A very powerful group of filters are the morphological filters. They are based on the shape of an object and gain information or modify that shape.

Now back to topic. The closing filter. It is a filter that allows you close holes in an image. If you do some background subtraction you will always have some holes inside your image (if you do not use a special light setup). So what do we need? A fast and working closing filter.
Continue reading ‘Closing in Flash’

Flashforum Konferenz 2006

I will attend the german FFK06 this year. I am also very happy that I may hold two sessions. The first will be about new AS3 techniques and possibilities and the second one about optimizations and performance regarding the new AVM2.

Real-time background subtraction (Updated)

This is a quick test I made regarding background-substraction in Flash (which is also called Scene building etc.). I wanted to test this because of another experiment which I have in mind. The result is very nice, and it is acceptable fast.

A simplified description of the used technique. First of all I have the WebCam and a Video. A (grayscale) Snapshot of the scene will be taken which is called background. The background should not include the things you want to extract. From that moment on you create a grayscale picture from the webcam and substract the background from it. I draw the video onto the screen and for every pixel that has a difference greater than 8 I copy a pixel from the original webcam image.

Have a look
[as]var frame: BitmapData = webcam.getCurrentFrame();
videoBitmap.draw( videoDisplay );

//– create grayscale image of webcam frame
buffer.applyFilter( frame, frame.rect, new Point, bt709 );

//– substract the background
buffer.draw( background, null, null, ‘difference’ );

//– apply threshold
buffer.paletteMap( buffer, buffer.rect, new Point, null, null, alphaMap );

//– create mask using alpha channel
frame.copyChannel( buffer, buffer.rect, new Point, BitmapDataChannel.BLUE, BitmapDataChannel.ALPHA );

//– draw
smallScreen.draw( videoBitmap );
smallScreen.draw( frame );
screen.draw( smallScreen, scale );[/as]

I updated the way the resulting picture is drawn (thanks André!). Therefore the alpha-channel is abused as a mask applied with some thresholding. Instead of BitmapData.threshold I use BitmapData.paletteMap with a pre-cached table because it is a little bit faster. It is much better using the alpha-channel as a mask because of smooth edges. One last problem: Using only the Y-channel of a picture results in to many holes in the resulting image. I will try the same with three dimensions instead of one.

Demo

Voxel engine with terrain generation based on spectrum analysisIt was definitly not my time when demos were so popular. But it is fun to create something like that because of speed optimizations, different techniques and of course the eyecandy.

I looked around the web and found the Demo Effects Collection which is a site that lists a lot of oldschool demo effects. I know only thoose new demos, using a lot of 3D. So this site is very helpful to get some idea about old effects and the techniques behind them.

Basically I want this demo to be some showcase to demonstrate new possibilities of Actionscript3. It will be fun creating it. The screenshot shows a Voxel engine with terrain generation based on spectrum analysis. The demo will feature a playback system and different scenes. The screen is 480x240px (!) and all effects are currently done in real-time. A release of the demo will be around 30th of november.

I am also very happy that BitShifter allowed me to use his music. Thanks Josh!

ImageProcessing Library (beta)

A first beta release of the imageprocessing library can be downloaded right now. I like to experiment with my webcam and images. This is a fast library with a couple of implemented algorithms. Have a try and tell me what you think about it.

ImageProcessing Library
ImageProcessing Library Documentation

Updates:

  • Added QuickSepia filter which is using a ColroMatrixFilter instead of YIQ transformations (de.popforge.imageprocessing.filters.color.QuickSepia)
  • Added Color.add() and Color.substract() for easier blend-mode calculations.
  • The zip-file contains now the laboratory sources and a batch to compile them.

ImageProcessing library

LevelsCorrectionGot an idea what imageprocessing means? You always wanted to create som eyeToy like game, but it is a struggle to fight against bad lighting? You know that AS3 is fast. So what about some real-time imageprocessing?

This is a personal point of interest and I had a lot of fun creating this library. It is currently in an early state but it is very difficult to create acceptable results. This library is not very scientific but the output is nearly the same. For some reasons I had to speed up some processes of real imageprocessing. I will continue the fun and add some filters. I do not know from which categorie, maybe morphologic or some more basic binary stuff like Erosion or Dilation (and therefore Closing).

Have a small preview here. I will post either the sources (after having another look) or a compiled SWC. But Flex Builder 2 is some sort of annoying. If I compile the SWC with the compc it works fine until I want to include the SWC into a project. The project also compiles but there is no auto-completion in Flex Builder.

ImageProcessing Library Documentation