以编程方式向图像添加凸面效果
我正在寻找一些算法来为图像添加凸面镜效果和凹面镜效果。我还想知道如何有效地实现这一点:将算法应用于图像数据或通过包含效果的透明图像覆盖它。但我认为第二种选择不适用于这种情况。
I am looking for some algorithms to add a convex mirror effect and concave mirror effect to an image. I want to know also how to make this efficiently: applying the algorithm to image data or overlay it by a transparent image that contains the effect. But I don't think the second choice is applicable in this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您手动执行此操作而不是使用硬件基元,那么布雷森汉姆插值算法(通常用于画线)就是最佳选择:错误传播比其他更复杂的方法高效得多。
布雷森汉姆所做的只是插值。不要错过在其他地方使用其高效设计的机会(线条绘制的坡度计算只是插值的众多应用之一:您可以插值另一个维度:2D、3D、透明度、反射、颜色等)。
25 年前,我记得曾用它来调整位图大小,甚至在实时 3D 引擎中进行纹理映射!当时图形加速视频板花费了一大笔钱......
If you are doing it manually instead of using hardware primitives, then the
bresenham interpolation algorithm
(usually used for line drawing) is the way to go: error propagation is far more efficient than other, more complex, methods.What Bresenham does is just interpolation. Don't miss the opportunity to use its efficient design elsewhere (slope calculation for line-drwaing is just one of the many applications of interpolation: you can interpolate another dimension: 2D, 3D, transparency, reflection, colors, etc.).
25 years ago, I remember having used it to resize bitmaps and even do texture mapping in a real-time 3D engine! That was at a time graphic-accelerated video boards costed a fortune...
CImg 库有一个鱼眼示例,位于 Examples\CImg_demo.cpp 中。核心算法看起来非常简单(而且速度很快,就像这个库一样)。我认为这是真实光学效果的近似值,但可以进行修改以处理凸面镜面。我不知道它是否可以扩展到处理“负”曲率。
CImg library has a fisheye sample, in examples\CImg_demo.cpp. The core algorithm seems very simple (and fast, as generally this library). I think it's an approximation of the real optical effect, but could be modified to handle the convex mirroring. I don't know if it could be extended to handle 'negative' curvature.
您可以使用
预先计算的 sin() 表
并插入值以匹配位图的大小。通过使用偏移量或更大的表可以实现相反的效果。还记得 80 年代 DOS 演示的(伟大时代)...
You can use a
pre-calculated sin() table
and interpolate values to match the size of your bitmap. The inverse effect is achieved by either using an offset or a larger table.Remembers me the (great times of the) DOS demos in the 80s...