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.

Closing is defined as a dilation followed by an erosion. The dilation is defined as

A \oplus B = \{ t \in \mathbb{R} : t = a + b, a \in A, b \in B \}

and the erosion as the complement

A \ominus B = (A^c \oplus B)^c

The definition of the closing filter is therefore

c(A,B) := (A \oplus B) \ominus B

A is the initial image and B a structuring function.

This was the theory and the reality? You can not work with a structuring function in Flash. BitmapData.setPixel and BitmapData.getPixel is to slow. What else? The BlurFilter seems to be an alternative followed by threshold techniques. I have a simple approach to this problem but I am not satisfied since it is slow and the result not very good.

[as]alphaMap = new Array( 0×100 );
edgeMap = new Array( 0×100 );

for ( var i: int = 0; i < 0x100; i++ )
{
alphaMap[ i ] = ( i > 0×10 ) ? 0xff : 0×00;
edgeMap[ i ] = ( i > 0×20 ) ? 0xff : i;
}

buffer.paletteMap( buffer, buffer.rect, origin, null, null, alphaMap );

for ( i = 0; i < 3; i++ )
{
buffer.applyFilter( buffer, buffer.rect, origin, new BlurFilter( 8, 8, 1 ) );
buffer.applyFilter( buffer, buffer.rect, origin, new BlurFilter( 4, 4, 1 ) );
}

buffer.paletteMap( buffer, buffer.rect, origin, null, null, edgeMap );

for ( i = 0; i < 3; i++ )
{
buffer.applyFilter( buffer, buffer.rect, origin, new BlurFilter( 8, 8, 1 ) );
buffer.applyFilter( buffer, buffer.rect, origin, new BlurFilter( 4, 4, 1 ) );
}[/as]

I have two test pictures. The input image and the output how it should look like. Borders can be smooth. But this is how the output should look like.

Before

After

Any suggestions are welcome. I will have to do more tests.

Related Posts

0 Responses to “Closing in Flash”


  1. No Comments

Leave a Reply






Close
E-mail It