How to change thin image to fat image in iPhone SDK?

image-processing, iphone

Solution

As it happens, I'm working on something almost exactly like what you describe for our company right now. We're tackling faces, which is an easier problem to do realistically.

Here is a before image (of yours truly)

And here it is with a "fat face" transformation:

What I did is to import the image into an OpenGL texture, and then apply that texture to a mesh grid. I apply a set of changes to the mesh grid, squeezing certain points closer together and stretching others further apart. Getting a realistic fat face took a lot of fine-tuning, but the results are quite good, I think.

Once I have the mesh calculated, OpenGL does the "heavy lifting" of transforming the image, and very fast. After everything is set up, actually drawing the transformed image is a single call.

Here is the same image, showing the grid lines:

Fat face with grid lines http://imageshack.com/a/img404/8049/afterwithlines.jpg

It took me a couple of weeks of full-time work to get the basic mesh warping working (for a client project that fell through) and then another week or so part time to get the fat face layout fine-tuned. Getting the whole thing into a salable product is still a work in progress.

The algorithm I've come up with is fast enough to apply the fat transformation (and various others) to video input from an iOS camera at the full 30 FPS.

In order to do this sort of image processing you need to understand trig, algebra, pointer math, transformation matrixes, and have a solid understanding of how to write highly optimized code.

I'm using Apple's new Core Image face recognition code to find peoples face features in an image, and use the coordinates of the eyes and mouth as the starting point for my transformations.

Your project is much more ambitious. You would have to do some serious image processing to find all the features, trace their outlines, and then figure out how to transform the image to get a convincing fat effect. You'd need high resolution source images that were posed, lit, and shot under carefully controlled conditions in order to get good results.

It might be too much for the computing power of current iOS devices, and the kind of image recognition you'd need to do to figure out the body parts and how to transform them would be mind-bendingly difficult. You might want to take a look at the open source OpenCV project as a starting point for the image recognition part of the problem.

Problem

Hi, is there any way to change your image thin size to fat size vice-versa in iPhone SDK? In this application I want to provide the user a possibility to change its image from regular size to fat size by sliding the slider he can measure its size in iPhone SDK? I think this can be worked by getting pixels of image i have tried this code to get pixels of image but it just removes colors from the image. ``` UIImage *image = [UIImage imageNamed:@"foo.png"]; CGImageRef imageRef = image.CGImage; NSData *data = (NSData *)CGDataProviderCopyData(CGImageGetDataProvider(imageRef)); char *pixels = (char *)[data bytes]; // this is where you manipulate the individual pixels // assumes a 4 byte pixel consisting of rgb and alpha // for PNGs without transparency use i+=3 and remove int a for(int i = 0; i < [data length]; i += 4) { int r = i; int g = i+1; int b = i+2; int a = i+3; pixels[r] = pixels[r]; // eg. remove red pixels[g] = pixels[g]; pixels[b] = pixels[b]; pixels[a] = pixels[a]; } // create a new image from the modified pixel data size_t width = CGImageGetWidth(imageRef); size_t height = CGImageGetHeight(imageRef); size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef); size_t bitsPerPixel = CGImageGetBitsPerPixel(imageRef); size_t bytesPerRow = CGImageGetBytesPerRow(imageRef); CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, [data length], NULL); CGImageRef newImageRef = CGImageCreate ( width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, false, kCGRenderingIntentDefault // the modified image UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; imgView.image = newImage; ``` I have also tried by stretching image from this code. ``` UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:10 topCapHeight:10]; ``` Can anybody help me? I didn't find any framework or SDK that gives me that kind of functionality. I have googled for long time.

Original source