AGGeometryKit icon indicating copy to clipboard operation
AGGeometryKit copied to clipboard

Better resampling of images with AGKTransformPixelMapper

Open hfossli opened this issue 11 years ago • 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.

hfossli avatar Sep 12 '14 08:09 hfossli

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

hfossli avatar Sep 12 '14 08:09 hfossli

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.

snown avatar Sep 30 '14 21:09 snown

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? :)

hfossli avatar Oct 01 '14 11:10 hfossli

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?

hfossli avatar Mar 15 '16 14:03 hfossli

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

hfossli avatar Apr 15 '16 12:04 hfossli