Page 1 of 1

Paint the image magick comparision output

Posted: 2019-12-04T17:56:52-07:00
by shahire
Hello,
I am using ImageMagick 7 for our visual testing framework.i am using below command to compare the images,

Code: Select all

magick compare -highlight-color magenta -lowlight-color transparent  -metric RMSE -fuzz 10% image1.png image2.png -compose exclusion diff.png
However i want to paint the difference instead of source and destination content overlapping with magenta color.
Could you please provide some pointer how i can achieve using image magick.

Re: Paint the image magick comparision output

Posted: 2019-12-04T18:04:50-07:00
by fmw42
Perhaps you would be better using -compose difference -composite and then color the result

Code: Select all

magick image1.png image2.png -compose difference -composite -auto-level +level-colors black,red result.png
or

(unix syntax)

Code: Select all

magick image1.png image2.png -compose difference -composite -auto-level \
\( xc:red xc:orange xc:yellow xc:green1 xc:cyan xc:blue xc:blueviolet xc:black \
+append -flop -filter Cubic -resize 600x1! \) -clut result2.png
Please always provide your exact IM version and platform/OS as syntax may vary

Re: Paint the image magick comparision output

Posted: 2019-12-04T22:53:09-07:00
by shahire
Thanks for quick solution.

Following is the IM version,
Version: ImageMagick 7.0.9-5 Q16 x86_64 2019-11-18 https://imagemagick.org
Operating Systems - unix

Actually i want to highlight the diff with magenta color so that all content would be visible,

Could you please check diff images on below URL, i am looking for the similar output from ImageMagick
https://help.applitools.com/hc/en-us/ar ... iff-Images

Re: Paint the image magick comparision output

Posted: 2019-12-05T11:37:13-07:00
by fmw42
Perhaps this is what you want.

Input:

Image

Image

Unix syntax (highlight color is blue)

Code: Select all

convert lena_text.png -write mpr:img lena.png \
-compose difference -composite -threshold 0 \
\( +clone -fill blue -colorize 100 \) \
mpr:img \
-reverse \
-compose over -composite \
lena_diff.png
Image

Re: Paint the image magick comparision output

Posted: 2019-12-05T17:55:25-07:00
by shahire
With given command close to what i am looking for, however the difference is overlapping with base image text/content.I want figure out the difference and paint region on base image.
Could please check below URLs with expected output and what we are getting by your command,
https://drive.google.com/drive/folders ... p=sharing

Re: Paint the image magick comparision output

Posted: 2019-12-05T19:13:19-07:00
by fmw42
Imagemagick cannot do that, since it cannot identify text words. You could conceivably find the bound of the difference and fill that in. But you cannot highlight individual words with any reliability, in my opinion without some kind of OCR character recognition.

Re: Paint the image magick comparision output

Posted: 2019-12-05T23:24:31-07:00
by shahire
Really appreciate your quick help.

Re: Paint the image magick comparision output

Posted: 2019-12-06T10:19:20-07:00
by fmw42
Perhaps this will help. It finds the bounds of the differences and then draws a rectangle

Code: Select all

bounds=`magick before.png after.png \
-threshold 55% \
-compose minus -composite \
-format "%@" info: | tr "x" "+"`

ww=`echo $bounds | cut -d+ -f1`
hh=`echo $bounds | cut -d+ -f2`
xo=`echo $bounds | cut -d+ -f3`
yo=`echo $bounds | cut -d+ -f4`
x1=$xo
y1=$yo
x2=$((xo+ww-1))
y2=$((yo+hh-1))

magick before.png \
-fill "rgba(255,0,0,0.25)" \
-draw "rectangle $x1,$y1 $x2,$y2" \
before_diff2.png
Image

Code: Select all

bounds=`magick after.png before.png \
-threshold 55% \
-compose minus -composite \
-format "%@" info: | tr "x" "+"`

ww=`echo $bounds | cut -d+ -f1`
hh=`echo $bounds | cut -d+ -f2`
xo=`echo $bounds | cut -d+ -f3`
yo=`echo $bounds | cut -d+ -f4`
x1=$xo
y1=$yo
x2=$((xo+ww-1))
y2=$((yo+hh-1))

magick after.png \
-fill "rgba(0,0,255,0.25)" \
-draw "rectangle $x1,$y1 $x2,$y2" \
after_diff2.png
Image