本文介绍了在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

推荐答案


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 ++中对图像的玻璃效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:41