agens-no/AGGeometryKit

Better resampling of images with AGKTransformPixelMapper

hfossli opened this issue · 5 comments

As of today we are just using nearest neighbor algorithm. This looks really bad both when downsampling and upscaling.

Creating an alternative version of AGKTransformPixelMapper using some more sophisticated algorithm would be awesome. Here's some code hosted on google which does bicubic interpolation.

@snown What do you think? Is this something you would like to have a look at?

Sorry for the delay, yeah I'll take a crack at this. I'm up against a deadline right now, but I may have a couple extra cycles soon. Feel free to assign.

Thanks.

Cool :) It will definitely be boosting the quality of the output which again will be a huge improvement of this crop-to-quad-feature!

Should we use the accelerate-framework? :)

Hey @snown, I've been thinking. iOS 7 has been around for quite some time now. Before iOS 7 we couldn't render layers/uiview with 3d transforms to images. With iOS 7 that became possible. Our resampling is inferior to UIKit's version. It is now possible to do something like this

// 1. Create a imageview
UIImageView *imageView = [UIImageView new];

// 2. Apply a transform
imageView.transform = ...;

// 3. Apply image
imageView.image = image;

// 4. Position it
imageView.layer.position = ...;

// 3. Add it to a container
UIImageView *container = [UIImageView new];
[container addSubview:imageView];

// 6. Render that container
CGSize size = ...;
CGRect rect = ...;
CGFloat scale = ...;
UIGraphicsBeginImageContextWithOptions(size, NO, scale);
[container drawViewHierarchyInRect:rect afterScreenUpdates:YES];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// 7. Crop the result
UIImage *final = [correctedImage imageByCroppingToRect:destinationRect];

Maybe we could update that imageByCroppingToQuad:destinationSize: to do something along these lines instead? I don't know how to calculate the proper transform, maybe you do?

Useful stuff! We can throw our resampler out the window! Anyone have time to do a PR for that?
http://flexmonkey.blogspot.no/2016/04/a-look-at-perspective-transform.html