This project for the Advanced Image Synthesis class had the objective to simulate lens flare effect in an image automatically. The brightest spot would be found using histograms and then used as a source for the effect. This project was implemented in Java. Lens flares are generated in real life by reflection, scattering and refraction of the light through different lenses.
Although in some situations lens flares are avoided because of two important reasons: image contrast reduction and it adds light to dark areas; lenses flares effects are very common on post-production of images/footage where artificial CGI elements are composited in order to add a sense of realism, and also sometimes is being used to add a sense of drama and sophistication to the image.
Physical mechanisms in lenses and physiological structure of the eye creates a space where incoming light can be reflected, scattered and diffracted. These mechanisms are scattering in the cornea, lens and retina and diffraction in the coherent cell structures on the outer radial areas of the lens [1].
For good optical systems and most of the images the flare effects is distributed across the image; therefore, it is not noticeable by the viewer, but if the image includes a very light source, then the flare effect can have enough intensity to be visible.
Other physical elements such as special lenses, zooms and even the eyelashes may contribute to stronger image artifacts and a brighter flare, due to internal scattering in different layers of lenses and diffraction artifacts due to eyelashes.
In this project, we will go through the implementation and generation of a lens flare effect with procedural textures and image segmentation to find brighter spots on image.
Although the physical mechanism behind the light scattering in the eye is understood, the exact structure of the cells in the eye is not completely know to the extent that we can simulate the light behavior [1].
A physical accurate model of the light behavior in lenses and eye will need to be implemented using ray tracing and some linear equations. Unfortunately, this technique is not fast enough for a "real-time" interaction in a production pipeline, and more importantly it does not allow the user to create more dramatic and artistic flare effects that are being used in production.
There fore an "image based" technique is used to create lens flare effects, that is, we decompose the effect in all of its core elements and create procedural textures that can be composited later, it is not uncommon in video games that actual pre-fabricated texture images are used in order to save resources.
The bloom or glow is caused by scattering and diffraction. This glow is located at the center of the light source (source of the lens flare). The following is the implementation code in the Java language:
Lenticular halos (halo + ring + spike) are caused by the circular optical grating formed by the radial fibers at the perophery of the crystalline lens [1].
Rings go hand in hand with the halo in order to increase the intensity, the rings are centered at the source along the bloom and a halo.
The implementation for the spikes are based in particles. That is we start at a randome angle and we start painting additive particles across its radius.
After you have all the textures for the elements of the lens flare, then the next step is to organize these textures.
Original Image
Brightest blob
Lens Flare result
Original Image
Lens Flare Result
By using a modified version of our textures, we can simulate some diffractive anomalies on the lenses such as dirt orbs, rain orbs and eyelashes diffraction. We used textures using the Screen and Add blending modes, box blur and directional blur filter kernels. The following two pictures show an experimentation:
[1] Spencer, G., Shirley, P., Zimmerman, K., and Greenberg, D. P. 1995. Physically-based glare effects for digital images. In Proceedings of the 22nd Annual Conference on Computer Graphics and interactive Techniques S. G. Mair and R. Cook, Eds. SIGGRAPH '95. ACM, New York, NY, 325-334. DOI= http://doi.acm.org/10.1145/218380.218466
[2] Lens Flares by Alan Gordie
[3] Understanding Camera Lens Flares
[4] Lens Flares - Wikipedia
[5] Fast OpenGL Rendering of Lens Flares
[6] Lens Flares Effects
[7] The Art of Modeling Lens Flares
[8] Thresholding (image Processing)
[9] Segmentation
[10] Thresholding and Segmentation