在java中实现像photoshop那样的液化滤镜的最基本方法是什么?

发布于 2024-09-27 19:04:39 字数 46 浏览 6 评论 0原文

在 Java 中实现像 Photoshop 那样的液化滤镜的最基本方法是什么?

What is the most basic approach to implement a liquify filter like the one photoshop has , in java ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的心境我的脸 2024-10-04 19:04:39

基本上,您有一个源图像和一个网格。网格开始时是一个具有完美正方形的网格,但会变形。该算法是

  For Each section of the mesh
     For Each pixel of the section
         (x, y) = Location in original photo for this pixel // (floating point)
         color = ColorFromOriginal(x, y) // this needs to blend neighboring pixels if fractional
         setColor(color)

计算出 (x, y) 是简单的几何图形 - 将变形正方形的中心映射到原始正方形的中心,然后计算出您所在的三角形 (N, S, E, W) 并映射变形后的三角形恢复到原来的样子。

  +---------+
  |\       /|
  | \  N  / |
  |  \   /  |
  |   \ /   |
  | W  X  E |
  |   / \   |
  |  /   \  |
  | /  S  \ |
  |/       \|
  +---------+

一旦你有了浮点数的 (x, y),通过混合与该浮点重叠的四个像素来计算它的颜色。坐标重叠的比例。

整数像素

   +----+----+----+
   |    |    |    |
   |    |    |    |
   +----+----+----+
   |    |    |    |
   |    |    |    |
   +----+----+----+
   |    |    |    |
   |    |    |    |
   +----+----+----+

浮动点。其上重叠的像素

   +----+----+----+
   |    |    |    |
   |   x|xx  |    |
   +----+----+----+
   |   x|xx  |    |
   |    |    |    |
   +----+----+----+
   |    |    |    |
   |    |    |    |
   +----+----+----+

结果颜色是四个像素按其重叠程度的比例混合而成的。

这正是调整大小(重新采样)的算法——网格没有变形,只是放大,因此三角形步骤是不必要的,但这是相同的想法。

Basically, you have a source image and a mesh. The mesh starts as a grid with perfect squares, but gets deformed. The algorithm is

  For Each section of the mesh
     For Each pixel of the section
         (x, y) = Location in original photo for this pixel // (floating point)
         color = ColorFromOriginal(x, y) // this needs to blend neighboring pixels if fractional
         setColor(color)

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.

  +---------+
  |\       /|
  | \  N  / |
  |  \   /  |
  |   \ /   |
  | W  X  E |
  |   / \   |
  |  /   \  |
  | /  S  \ |
  |/       \|
  +---------+

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

   +----+----+----+
   |    |    |    |
   |   x|xx  |    |
   +----+----+----+
   |   x|xx  |    |
   |    |    |    |
   +----+----+----+
   |    |    |    |
   |    |    |    |
   +----+----+----+

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.

贩梦商人 2024-10-04 19:04:39

您正在寻找的基本上是一个扭曲过滤器,您可以查看: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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文