Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage nonlinear resizing

I have unicolor image and i need to resize some parts from it, with different scale. Desired result is showed at image. I've looked at applying grid mesh in opengles but i could not find some sample code or more detailed tutorial. I've also looked at imgwrap but as far i can see this library requires qt framework. Any ideas, sample code or links for further read will be appreciated, thanks.enter image description here

like image 833
Ivan Alek Avatar asked Jun 25 '13 11:06

Ivan Alek


1 Answers

The problem you are facing is called "image warping" in computer graphics. First you have to define some control points in the original image and corresponding points in a sample destination image. Then you have to calculate a dense displacement field (in this application called also wrapping grid) and simple apply this field to the original image.

More practically: your best bet on iOS will be to create a 2D grid of vertices in OpenGL. Map your original image as a texture over this grid and deform the original grid by displacing some of its points. Then you simple take a screenshot of the resulting image with glReadPixels.

I do not know any CIFilter that would implement displacement field mapping of this kind.

UPDATE: I found also an example code that uses 8 control points to morph images with OpenCV. http://engineeering.blogspot.it/2008/07/image-morphing-with-opencv.html

OpenCV has working ports to iOS, so you could simple experiment with the code on the link above also on a target device.

like image 56
MrTJ Avatar answered Sep 20 '22 13:09

MrTJ