Akshay Gawade
Apr 24, 2021

How to compare image on pixel data? And How to compare color of two images using colorAbsoluteDifference CIFilter?

To compare image on pixel data you need CGImage object of UIImage.

Sometime when you create computed image through CIFilter and directly create UIImage from CIImage. It does not have CGImage data, so we need to covert CIImage to CGImage first and then get pixel data to compare

Get pixel data of images and compare through == operator.

There is other way to do this through CIFilter.colorAbsoluteDifference() which get available from iOS 14 Explore Computer Vision APIs — WWDC 2020 — Videos — Apple Developer

Following code shows how to compare two images using colorAbsoluteDifference which return the image with difference of two images.