Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created July 29, 2022 12:19
Show Gist options
  • Save anupamchugh/1c48a08cb452531931ce3920abc0f63a to your computer and use it in GitHub Desktop.
Save anupamchugh/1c48a08cb452531931ce3920abc0f63a to your computer and use it in GitHub Desktop.
func computeImageDifference(){
guard let inputImage = UIImage(named: input1)
else { return }
guard let inputImage2 = UIImage(named: input2)
else { return }
let beginImage = CIImage(image: inputImage)
let beginImage2 = CIImage(image: inputImage2)
let context = CIContext()
let currentFilter = CIFilter.colorAbsoluteDifference()
currentFilter.inputImage = beginImage
currentFilter.inputImage2 = beginImage2
guard let outputImage = currentFilter.outputImage
else {return }
if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) {
let uiImage = UIImage(cgImage: cgimg)
self.image = uiImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment