|
Finally.
Source: (idea custom); implementation issues: [PITA00:122-124], [HOLZ88:60-61], [DEVE01], [CLAE97]
A week before this project was due, I realized that I had not yet implemented the raindrop effect that I had been ‘studying’ and preparing for all year. Instead of writing this document at that time, I spent the weekend working on the most rewarding filter of the entire project. Obviously, there is much room for improvement on this filter, but the results as they stand to date are inspiring given the relatively little time I spent on its actual implementation.
As mentioned before, this filter was initially meant to produce an image that would emulate what a viewer might see as he or she were looking through a window just after it had rained. I envisioned small fish-eye lens effects randomly place over the image, which would make the circular area appear magnified under the water. After seeing the results, I guess a better name might be ‘condensation’, as the effect of the water magnification only works when the water drop is directly on top of the image it is magnifying. Sure, raindrops are noticeable when looking through a wet window, but the areas under those drops are not clearly magnified (at least not as the results of this filter produce). I applied the filter to a close up photograph of a dry pop can (i.e. without condensation). The results were eerily
realistic:

Figure 4: Photo taken of a Pepsi can with a digital camera and
Raindrop filter applied
The ‘raindrops’ are small randomly placed circles of varying size throughout the image, so that no circle overlaps another circle. Each circle area is processed with a small fish-eye lens effect, and a highlight and shadow are added to produce a three-dimensional effect. After the fish-eye lens modification and the addition of highlight and shadow, the circle is slightly blurred to remove the pixelation that the fish-eye effect produces and to soften the highlight and shadows. Through a dialog box, the user determines the size of the largest raindrop and the raindrop density. If the algorithm cannot fit all the raindrops the density variable requests (due to small image size or large raindrops) it will simply stop, with most of the area (but not all) covered by ‘water drops’.
As may or may not be obvious, the raindrop filter uses a combination of all three filter types described in this report: point, area, and geometric, and uses pieces of each of the following filters: hue / saturation (for the highlight and shadow), blur (for smoothing the water drop), fish-eye lens (for magnification), and random blur (for the randomly placed raindrops).
The basic algorithm I used is outlined below. However, the actual implementation is about four pages long when printed out on my printer. There are many subtle modifications made to this outline in my implementation in order to produce a realistic effect and many more details that I wish not to reproduce here. The interested reader is invited to study the actual code.
w = 0.4; // this value seemed to produce the right
// amount of curvature (see fish-eye lens)
for every pixel in the image do
// copy the imahe since the entire image won't be
affected
filterpixel = currentpixel;
for num_of_raindrops do
{
size = rand() * (MAX_SIZE / RAND_MAX);
R = size / 2;
s = R / log(w*R+1); // recall fish-eye variable
do
{
x = rand() * image_height-1 / RAND_MAX;
y = rand() * image_width-1 / RAND_MAX;
} while (this (x,y) value will produce a raindrop that
will overlap an existing raindrop);
for pixels inside the circle centered at (x,y) of radius R do
{
convert (x,y) to polar;
do fish-eye lens transformation;
if (currentpixel is in highlight area)
{
filterpixel.r += highlight_increment;
filterpixel.g += highlight_increment;
filterpixel.b += highlight_increment;
}
else if (currentpixel is in shadow area)
{
filterpixel.r -= shadow_decrement;
filterpixel.g -= shadow_decrement;
filterpixel.b -= shadow_decrement;
}
}
for pixels inside the circle centered at
(x,y) of radius R do
{
blur the pixel as done before;
}
}
As noted, there are obvious enhancements that could be made to this filter. One of those is that of a variable light source for producing the shadow and highlight. Now, all shadows and highlights are located in the same area on all raindrops and we assume a distant light source. Another (more difficult) modification would be to make the raindrops less round. No water drop is perfectly circular, however, at this point, I am not sure how one would implement an ‘amoeba-shaped’ drop of water with similar magnification as is shown here.

Raindrops (default settings)
Return to
the list of filters
|