Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glass Effect - Artistic Effect

I wish to give an effect to images, where the resultant image would appear as if we are looking at it through a textured glass (not plain/smooth)... Please help me in writing an algo to generate such an effect.

Here's an example of the type of effect I'm looking for

The first image is the original image and the second image is the output im looking for.

like image 646
megha Avatar asked Jan 11 '10 06:01

megha


People also ask

What is frosted glass effect?

Frosted glass is produced by the sandblasting or acid etching of clear sheet glass. This creates a pitted surface on one side of the glass pane and has the effect of rendering the glass translucent by scattering the light which passes through, thus blurring images while still transmitting light. It has 10-20% Opacity.


2 Answers

Begin by creating a noise map with dimensions (width + 1) x (height + 1)that will be used displace the original image. I suggest using some sort of perlin noise so that the displacement is not to random. Here's a good link on how to generate perlin noise.

Once we have the noise we can do something like this:

Image noisemap; //size is (width + 1) x (height + 1) gray scale values in [0 255] range
Image source; //source image
Image destination; //destination image
float displacementRadius = 10.0f; //Displacemnet amount in pixels
for (int y = 0; y < source.height(); ++y) {
    for (int x = 0; x < source.width(); ++x) {
        const float n0 = float(noise.getValue(x, y)) / 255.0f;
        const float n1 = float(noise.getValue(x + 1, y)) / 255.0f;
        const float n2 = float(noise.getValue(x, y + 1)) / 255.0f;
        const int dx = int(floorf((n1 - n0) * displacementRadius + 0.5f));
        const int dy = int(floorf((n2 - n0) * displacementRadius + 0.5f));
        const int sx = std::min(std::max(x + dx, 0), source.width() - 1); //Clamp
        const int sy = std::min(std::max(y + dy, 0), source.height() - 1); //Clamp
        const Pixel& value = source.getValue(sx, sy);
        destination.setValue(x, y, value);
    }
}
like image 123
Andreas Brinck Avatar answered Oct 18 '22 07:10

Andreas Brinck


I can't offer you a specific example, but the gamedev forums & articles sections have lots of gold for image processing, 3d rendering, and the like. For instance, here is an article talking about using convolution matrices to apply similar effects to images that might be a good starting point.

like image 42
Scott Avatar answered Oct 18 '22 07:10

Scott