在C/C ++中对图像的玻璃效果 [英] Glass Effect on Image in C/C++

查看:106
本文介绍了在C/C ++中对图像的玻璃效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对图像产生效果,使生成的图像看起来就像我们通过带纹理的玻璃(不是平整/光滑的玻璃)观看时一样...请帮助我编写一种算法来产生这种效果
查看以下链接以查看我正在寻找的效果类型
http://picasaweb.google.com/megha19sudan/ArtisticEffects# [

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
view the following link to see the type of effect i''m looking for
http://picasaweb.google.com/megha19sudan/ArtisticEffects#[^]

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

推荐答案

Do the answers to this post[^] help you?



EDIT (After the link with the example):
It looks like the pixels of the bounding areas of a color are getting moved with a certain offset inside a little circle.

Maybe you can try that, check the wide of a color and moving the pixels inside the "border - x(your distorsion range)" with a random offset (x + random, y + random) where random inside [-a, a] being "a" your distorsion level.


通过创建尺寸(宽度+ 1)x(高度+ 1)的噪波贴图开始使用,以替换原始图像.我建议使用某种Perlin噪声,以使位移不是随机的.
听到噪音后,我们可以执行以下操作:

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.
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 + 5f));
        const int dy = int(floorf((n2 - n0) * displacementRadius + 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&amp; value = source.getValue(sx, sy);
        destination.setValue(x, y, value);
    }
}


这篇关于在C/C ++中对图像的玻璃效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆