在java中实现像photoshop那样的液化滤镜的最基本方法是什么?
在 Java 中实现像 Photoshop 那样的液化滤镜的最基本方法是什么?
What is the most basic approach to implement a liquify filter like the one photoshop has , in java ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,您有一个源图像和一个网格。网格开始时是一个具有完美正方形的网格,但会变形。该算法是
计算出 (x, y) 是简单的几何图形 - 将变形正方形的中心映射到原始正方形的中心,然后计算出您所在的三角形 (N, S, E, W) 并映射变形后的三角形恢复到原来的样子。
一旦你有了浮点数的 (x, y),通过混合与该浮点重叠的四个像素来计算它的颜色。坐标重叠的比例。
整数像素
浮动点。其上重叠的像素
结果颜色是四个像素按其重叠程度的比例混合而成的。
这正是调整大小(重新采样)的算法——网格没有变形,只是放大,因此三角形步骤是不必要的,但这是相同的想法。
Basically, you have a source image and a mesh. The mesh starts as a grid with perfect squares, but gets deformed. The algorithm is
Figuring out the (x, y) is simple geometry -- map the center of the deformed square to the center of the original, then figure out which triangle you are in (N, S, E, W) and map the deformed triangle to the original.
Once you have the (x, y) in floating point, calculate it's color by blending the four pixels that overlap that floating pt. coordinate in the ratio of the overlap.
Integer pixels
Floating pt. pixel overlaid on it
The result color is the blending of the four pixels in the ratio of how much it overlaps.
This is exactly the algorithm of a resize (resample) -- The mesh is not deformed, just enlarged, so the triangle step is unnecessary, but it's the same idea.
您正在寻找的基本上是一个扭曲过滤器,您可以查看:http://www.jhlabs。 com/ip/filters/ 我猜你正在寻找的是 http: //www.jhlabs.com/ip/filters/WarpFilter.html
希望有帮助
What you are looking for is basically a warp filter, you can check out: http://www.jhlabs.com/ip/filters/ and I guess what you are looking for is http://www.jhlabs.com/ip/filters/WarpFilter.html
Hope that helps