- Tanner Helland (dot) Com - http://www.tannerhelland.com -

Real-time Diffuse (Spread) Image Filter in VB6

Posted By Tanner On July 1, 2011 @ 5:23 pm In Graphics Code,Programming | No Comments

A set of camera diffusion lenses.

In traditional photography and film, a diffusion filter is used to soften light from a flash or stationary lamp.  Specialized lenses are available for this purpose, but the effect can be cheaply replicated by smearing petroleum jelly over the light (seriously [1]) or by shooting through a sheet of nylon.

In image processing, a diffusion filter often means something else entirely.  Photoshop’s “Diffuse” filter randomly rearranges pixels within a set radius.  (GIMP can do the same thing, but the effect is more accurately titled “Spread.”)  This effect can be animated for a cheap explosion effect – something a number of SNES, Genesis, and DOS games used to great effect.

This project demonstrates a simple, real-time method for replicating such an effect.  All code is commented and reasonably optimized, and an animated “special effect” version is provided for those interested.  Unlike Photoshop, this routine allows you to specify separate horizontal and vertical max random distances, as well as the ability to wrap pixels around image edges.

Here's the original image (a poster for LittleBigPlanet)

Here is the same image with a diffuse filter applied (max distance=5)

...and here is the image again, but with max distance = 50

...and one more example. This time, edge wrapping has been enabled. Note the bleed of planet pixels at the top and black pixels at the bottom.


Article printed from Tanner Helland (dot) Com: http://www.tannerhelland.com

URL to article: http://www.tannerhelland.com/3601/realtime-diffuse-spread-image-filter-vb6/

URLs in this post:

[1] seriously: http://en.wikipedia.org/wiki/Diffusion_filter

All text copyright © 2008 Tanner Helland. To reduce paper and ink usage, all comments, images, and videos have been suppressed on this printing.