在C/C ++中对图像的玻璃效果

编程入门 行业动态 更新时间:2024-10-19 02:15:00
本文介绍了在C/C ++中对图像的玻璃效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望对图像产生效果,使生成的图像看起来就像我们通过带纹理的玻璃(不是平整/光滑的玻璃)观看时一样...请帮助我编写一种算法来产生这种效果 查看以下链接以查看我正在寻找的效果类型 picasaweb.google/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 picasaweb.google/megha19sudan/ArtisticEffects#[^] the first image is the original image and the second image is the output im looking for

推荐答案

对这篇文章 [ ^ ]可以帮助您吗? 编辑(在带有示例的链接之后): 看起来颜色边界区域的像素在一个小圆圈内以一定的偏移量移动. 也许您可以尝试一下,检查颜色的宽度,然后在[border-x(您的失真范围)]内移动一个具有随机偏移量(x + random,y + random)的像素,其中[-a,a]内是随机的成为失真级别的"a". 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 ++中对图像的玻璃效果

本文发布于:2023-11-11 05:55:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中对   图像   效果   玻璃

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!