Search code examples
imagemagickimagemagick-convert

Compare pixels moved but similar images using ImageMagick


When comparing two images, both of the images are the same, except that in one of the images the text is moved by a couple of pixels. Please take a look at the below URL. It is a GIF that shows the difference of both the similar images.

https://giphy.com/gifs/9x50JjoLSPZ7lKRebk

My team initially used compare command which doesn't address this issue. Need suggestions please?


Solution

  • You can remove all the text in Imagemagick and just compare the bars by thresholding the Saturation/Chroma channel and then doing the compare. The text is gray, so it has little if any saturation. The bars are cyan, so they are colored and have a medium to high saturation.

    convert giphy.gif -colorspace HCL -channel g -separate +channel -threshold 5% +write tmp.gif miff:- | compare -metric rmse - null: 
    3164.96 (0.0482942)
    

    So this is 4.8% different.

    I save tmp.gif, which you do not need, only to show the result of the processing before the compare.

    enter image description here

    If your version of Imagemagick is too old and you do not have -colorspace HCL, then try HSL or HSB. C and S are similar and measure saturation/chroma.