An attempt to simulate an out-of-focus depth of field effect based on a depth map, plus a demonstration for the possibility to create blurs with smoothly increasing radius in Flash.
A depth map is a greyscale image which shows the distance of each pixel to the camera - white pixels are close, black pixels are far away (at least in my experiment, in other applications it may be the other way round). The depth map for this one looks like this:
Usually depth maps can be generated by 3D-Applications as an extra for a rendered scene, but as I used a normal photo I quickly drew the map manually with a few simple gradients. That's why it's not really exact, but it is good enough.
I'm not yet 100% satisfied with the outcome - as you will see there is a problem with the figure in front when she is out of focus - her body is blurred, but her outline stays sharp. The reason is that the depth map says that the area around her is actually behind her and is in focus - in reality her outline would be blurry and semi-transparent so you could see through the sharp background. To work around that I'd probably have to use a pixel-by-pixel solution which I fear might become too slow.
So here we go, just point the mouse to the area that should be in focus. I've added a few sliders so you can play with the depth of the focussed area and the length of the transition from sharp to blurry.
Regardingt the sharp-edges problem: could you handle this by performing a selective blur on the depth map? That is, when the woman is blurred, apply a woman-shaped to her outline on the depth map?
The problem is that currently the depth map itself is stupid, it is just another bitmap - it doesn't know that there is an outline of a woman somewhere in the picture. Though I might be able to use the convolution filter to detect hard edges in the depth map - which resemble areas where there is a big depth difference. Maybe add a little glow to these edges to enlarge them and yes - then I could create a selective blur on the final image only in these areas...
Anything that is cool is going take a big hit on the CPU I think, until Flash gives us a way to directly access the GPU.
Posted by: Funkmasterta on January 18, 2006 09:00 PM
Another problem is that the depth map is static. Doesn't real life DOF create blur that is becomes increasingly more blurry at an equal distance before and after the point of focus?
Great work delving into this possibity tho. This article about a plenoptic camera under development at Stanford may interest you: