iOS Swift: How to use or recreate Apple's contrast filter from the Photos app?

2020-02-15 ios swift image filter contrast

I want to apply a contrast filter to an image.

So far I'm using CIFilter.colorControls().contrast to reduce contrast of my image:

import Foundation
import UIKit
import CoreImage.CIFilterBuiltins

extension UIImage {
    func imageWithAdjustedContrast(contrast: Float, inContext context: CIContext) -> UIImage? {
        if let cgImage = cgImage {
            let colorControls = CIFilter.colorControls()
            colorControls.inputImage = CIImage(cgImage: cgImage)
            colorControls.contrast = contrast

            if let output = colorControls.outputImage {
                if let cgimg = context.createCGImage(output, from: output.extent) {
                    return UIImage(cgImage: cgimg)
        return nil

My original image: enter image description here

Reduced contrast of same image using my code snippet in my app: enter image description here

Apple's Photos app in iOS 13 produces a different result for reducing contrast: enter image description here

Is there a way to achieve the same result from Apple's Photos app?