There are many questions over here which checks if two images are "nearly" similar or not.
My task is simple. With OpenCV, I want to find out if two images are 100% identical or not.
They will be of same size but can be saved with different filenames.
Importing the packages we’ll need — matplotlib for plotting, NumPy for numerical processing, and cv2 for our OpenCV bindings. Structural Similarity Index method is already implemented for us by scikit-image, so we’ll just use their implementation
Then define the compare_images function which we’ll use to compare two images using both MSE and SSIM. The mse function takes three arguments: imageA and imageB, which are the two images we are going to compare, and then the title of our figure.
We then compute the MSE and SSIM between the two images. We also simply display the MSE and SSIM associated with the two images we are comparing.
Load images off disk using OpenCV. We’ll be using original image, contrast adjusted image, and our Photoshopped image
We then convert our images to grayscale
We will generate a matplotlib figure, loop over our images one-by-one, and add them to our plot. Our plot is then displayed to us.
Finally, we can compare our images together using the compare_images function.
Reference- https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
the sum of the differences should be 0 (for all channels):
You can use a logical operator like
xor
operator. If you are usingpython
you can use the following one-line function:Python
where
shape
is the property that shows the size of matrix andbitwise_xor
is as the name suggests. The C++ version can be made in a similar way!C++
Please see @berak code.
Notice: The
Python
code works for any depth images(1-D, 2-D, 3-D , ..), but theC++
version works just for 2-D images. It's easy to convert it to any depth images by yourself. I hope that gives you the insight! :)Doc: bitwise_xor
EDIT:
C++
was removed. Thanks to @Micka and @ berak for their comments.If they are same files except being saved in different file-names, you can check whether their Checksums are identical or not.