Skip to content

Instantly share code, notes, and snippets.

@StanDimitroff
Last active February 16, 2018 10:38
Show Gist options
  • Save StanDimitroff/0bc6db55ac8bbe2668e7ff5f012c5c69 to your computer and use it in GitHub Desktop.
Save StanDimitroff/0bc6db55ac8bbe2668e7ff5f012c5c69 to your computer and use it in GitHub Desktop.
Image noise reduction
extension UIImage {
var noiseReducted: UIImage? {
guard let openGLContext = EAGLContext(api: .openGLES2) else { return self }
let ciContext = CIContext(eaglContext: openGLContext)
guard let noiseReduction = CIFilter(name: "CINoiseReduction") else { return self }
noiseReduction.setValue(CIImage(image: self), forKey: kCIInputImageKey)
noiseReduction.setValue(0.02, forKey: "inputNoiseLevel")
noiseReduction.setValue(0.40, forKey: "inputSharpness")
if let output = noiseReduction.outputImage,
let cgImage = ciContext.createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment