What is the most basic approach to implement a liquify filter like the one photoshop has , in java ?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With