Formula to get comparing %

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Formula to get comparing %

Post by memerin »

Image

Image

I have this two image, using following command to compare they, i get in dif.txt:
compare %img1% %img2% -metric RMSE -subimage-search 2>diff.txt
13284.9 (0.202714)

I read that most closer than 0 is a full match, i would like ask help, writting a universal formula that could convert this value to a % value

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

percent = 100*(1-0.2020714) for RMSE. The value in parenthesis varies from 0 to 1.

memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Re: Formula to get comparing %

Post by memerin »

"13284.9" is the number of different pixels?
The images are 22x17 so 314 pixels, or im wrong?

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

No, that is the difference in in the quantumrange from 0 to 65535 (the min and max values for a Q16 default ImageMagick install). It is not the count. If you want to see the count, then use -metric AE

The percent above, does not count how many pixels are different. It is a value in the range from 0 to 100 for the rmse computed difference in color values.

memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Re: Formula to get comparing %

Post by memerin »

https://i.imgur.com/bRTQHN2.png

https://i.imgur.com/Wm7e9ZB.png
0.272303
Using your formula 100 * (1-0.272303) = 72,7
No way those two image be 72% matching

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

The 0.272303 was only for the one image that showed the result:
13284.9 (0.202714)

For results as:
xxxxxx (yyyyy)

use

percent = 100*(1-yyyyy)

But again, the result in percent is not an indication of the percent of pixels that matched. It is a score based upon the rms difference in color between the two images. For RMSE=0, that is a perfect match. Thus my equation would be 100%.

memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Re: Formula to get comparing %

Post by memerin »

Sorry i dont understand what you mean.

percent = 100*(1-0,202)
percent = 79,8

The images in my previous post, i dont think it match even 10%

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

If the overall colors are similar, but they do not match at each pixel, then you will still get a low match score using -metric rmse because the colors are similar. For example if both images are very dark, you will get low value for rmse. Every metric computes the differences differently. See https://imagemagick.org/Usage/compare/#statistics

If you want to count pixels that are different, then use -metric AE. It will give only one value, which is the count of how many pixels are different as long as their colors or gray levels differ by at least 1. More color difference at each pixel does not contribute.

Code: Select all

compare -metric ae Wm7e9ZB.png bRTQHN2.png null:
374

Your images are 22x17 = 374

So every pixel is different.

percent here is 100*374/(W*H) = 100*274/(22*17) = 100*1 = 100

memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Re: Formula to get comparing %

Post by memerin »

Can i use any kind of shade variation while comparing two images?

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

I do not understand the question? What do you mean by "shade variation"? compare has nothing to do with shading.

Are you asking about which metrics you can use? You can use any of the metrics listed by

Code: Select all

convert -list metric

memerin
Posts: 6
Joined: 2020-01-23T02:31:16-07:00
Authentication code: 1152

Re: Formula to get comparing %

Post by memerin »

Im using imagemagick + autoit, on autoit pixelsearch you cant set a shade-variation:

"shade-variation [optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the color. Default is 0 (exact match)."

I mean, i can use any option while comparing to allow similar pixels be detected as match?

User avatar
fmw42
Posts: 26294
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Formula to get comparing %

Post by fmw42 »

I still do not understand about shade variation. Perhaps you mean -fuzz XX%

Code: Select all

compare -metric ae -fuzz 10% image1 image2 diff
See https://imagemagick.org/script/command- ... s.php#fuzz and search for "fuzz" on https://imagemagick.org/Usage/compare/#statistics

Post Reply