Recipe 10.8. Detecting Edges


Problem

You want to detect the edges of a display object.

Solution

Use an edge detection matrix with a convolution filter.

Discussion

To apply an edge detection effect with a convolution filter, use a matrix with a negative value in the center surrounded by a symmetrical set of positive values, as described in the following generic matrix:

a   b   c d   e   d c   b   a

The following matrix applies a generic edge detection effect:

0   1   0 1  -3   1 0   1   0

The following applies the preceding edge detection effect to a display object:

sampleSprite.filters = [new ConvolutionFilter(3, 3, [0, 1, 0, 1, -3, 1, 0, 1, 0])];

The greater the center number, the less edge detection is applied. The following uses a center value of -1 with a divisor:

sampleSprite.filters = [new ConvolutionFilter(3, 3, [0, 1, 0, 1, -1, 1, 0, 1, 0], 3)];

See Also

Recipe 10.6




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net