Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Enhancing Images

I need to use apple's auto enhance images in my code. I'v found example that apple showed but I'm unable to make it work. I'm not actually sure what am I doing wrong.

Here is what apple recommended: AutoEnhanceCode

Here is what I'm doing (imageFinal is UIImage that I want to enhance):

- (IBAction)enhance:(id)sender {
  CIImage *myImage;
  CIImage *image = [imageFinal CIImage];
  NSDictionary *options = [NSDictionary dictionaryWithObject:[[image properties]valueForKey:kCIImageProperties] forKey:CIDetectorImageOrientation];
  NSArray *adjustments = [myImage autoAdjustmentFiltersWithOptions:options];
  for (CIFilter *filter in adjustments){
    [filter setValue:myImage forKey:kCIInputImageKey];
    myImage = filter.outputImage;
}

}

Error that I get is: Incompatible pointer types sending 'const CFStringRef' (aka 'const struct __CFString *const') to parameter of type 'NSString *'

I really don't know how to use this kCGImagePropertyOrrientation. I just want to apply that simple enhance.

Cheers.

like image 883
jovanjovanovic Avatar asked Oct 29 '25 03:10

jovanjovanovic


1 Answers

Here's a Swift version for Auto Enhancing a UIImage

extension UIImage {
    func autoEnhance() -> UIImage? {
        if var ciImage = CIImage.init(image: self) {
            let adjustments = ciImage.autoAdjustmentFilters()
            for filter in adjustments {
                filter.setValue(ciImage, forKey: kCIInputImageKey)
                if let outputImage = filter.outputImage {
                    ciImage = outputImage
                }
            }
            let context = CIContext.init(options: nil)
            if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) {
                let finalImage = UIImage.init(cgImage: cgImage, scale: self.scale, orientation: self.imageOrientation)
                return finalImage
            }
        }
        return nil
    }
}

Usage:

let autoEnhanced = image.autoEnhance() // returns optional UIImage
like image 53
Shachar Avatar answered Oct 31 '25 18:10

Shachar