Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warp Image area on touch of a point area?

I need a basic idea for how can i warp image on touch of a particular area. Image filters apply warp on whole image but i want to warp single point, like if i want to warp eye of a person then i will touch on that point. So I need a basic idea about this work.

I have tried this one but its also applies filters on whole image. https://github.com/Jtfinlay/PhotoWarp

App: https://play.google.com/store/apps/details?id=hu.tonuzaba.android&hl=en

like image 939
Joy Hard Avatar asked Jul 19 '17 06:07

Joy Hard


1 Answers

A warp is not just at a "single point" but over some area that you deform in a smooth way.

To achieve this, you need a geometric transform of the coordinates that works in some neighborhood of the touched point. One way to do this is by applying a square grid on the image and moving the grid nodes around the touched points with some law of yours (for instance, apply a displacement vector to all nodes, with a decaying factor such that far away nodes don't move).

Then you need a resampling function that computes the new coordinates of every pixel and copies the color of the source pixel.

For good results, you must actually work in reverse: scan the destination image and for every pixel retrieve the source coordinates and source pixels. Apply bilinear or bicubic resampling to avoid aliasing.

For ease of implementation, the gridding idea should be adapted as well: rather than deforming the destination grid, keep it unchanged and apply the inverse deformation to the source grid.

Last thing: in the grid approach, see the displacements of the grid nodes as two scalar functions DX(i, j) and DY(i, j) that you can handle separately. From the knowledge of the displacements at the nodes, you can estimate the displacement of any pixel by interpolation (bicubic would be appropriate here).

like image 119
Yves Daoust Avatar answered Nov 15 '22 19:11

Yves Daoust