V7 compare
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
V7 compare
If developers are thinking about about compare and v7, here's a suggestion.
A "-compare" operator could be added to convert and magick, working in a similar way to "-composite". It would do a comparison according to "-metric" etc, and make an output image just as the compare command currently does. However, it would also be influenced by a third image, if given, which acts as a mask. The text output would be available as an escape, eg "%[compare]".
The benefit is that, having created images in convert/magick, we wouldn't have to save results, exit convert, enter compare, and re-read the images.
It may be an easy addition to convert/magick. Or it might not, of course.
A "-compare" operator could be added to convert and magick, working in a similar way to "-composite". It would do a comparison according to "-metric" etc, and make an output image just as the compare command currently does. However, it would also be influenced by a third image, if given, which acts as a mask. The text output would be available as an escape, eg "%[compare]".
The benefit is that, having created images in convert/magick, we wouldn't have to save results, exit convert, enter compare, and re-read the images.
It may be an easy addition to convert/magick. Or it might not, of course.
snibgo's IM pages: im.snibgo.com
Re: V7 compare
It would be simple enough to support a -compare option for both IMv7 and 6. The returned value would likely be %[distortion]. We'll likely code up a solution in the next few weeks. Thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
Correct me if I am wrong but this would be a read mask in IM 6, which has not been implemented.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: V7 compare
The prime functionality I'd like is a "-compare" operator in convert, that does much the same thing as the compare command.
Using a third image as a mask is a nice-to-have addition. I'm not exactly sure what I'd like it to do. Probably, using RMSE as an example: the pixel difference of the first two images is multiplied by the pixel intensity of the third, then the difference is squared, then all the differences are summed to find the mean, which is then square-rooted.
Is this the same as a read mask would do? I don't know.
Using a third image as a mask is a nice-to-have addition. I'm not exactly sure what I'd like it to do. Probably, using RMSE as an example: the pixel difference of the first two images is multiplied by the pixel intensity of the third, then the difference is squared, then all the differences are summed to find the mean, which is then square-rooted.
Is this the same as a read mask would do? I don't know.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
No, as you explain it, it would be more like a write mask. The read mask would only process those pixel defined by the mask. The write mask processes all pixels and then filters by the mask after processing all pixels.is this the same as a read mask would do? I don't know.
Why can you not use -compose difference and then threshold on some appropriate value?
Sound like you want to compute the rmse values for every pixel in the two images with convert -compose ... -composite, (rather than compare, presumably to do other things in the convert in one command), then threshold the result.
You can compute the rmse difference images from scripting using compose difference on each channel, average the channels and use -evaluate pow 0.5 to compute the sqrt. Then get the average (mean) statistics from that image.
I do something similar only the metric is normalized cross correlation, in my script, simiar, at http://www.fmwconcepts.com/imagemagick/ ... /index.php
Try this to get the rmse error between the two same size images.
convert image1.png image2.png -compose difference -composite -separate +channel \
-poly "0.3333,2 0.3333,2 0.3333,2" -evaluate pow 0.5 -write rmse.png -format "%[mean] (%[fx:mean])" info:
rmse=sqrt( (r1-r2)^2 + (g1-g2)^2 +(b1-b2)^2) / 3 )
-poly does the squareing, adding and dividing by 3 (i.e multiply each square by 0.3333)
Of course my command line could be made into a new compose method, say -compose rmse and my script could be -compose ncc.
EDIT: Here are the command to do NCC, but it needs to be done in HDRI
ncc=(image1-mean1) * (image2-mean2) / (std1*std2)
infile1="cyclops.gif"
infile2="cyclops.gif"
convert $infile1 -colorspace gray 1tmp1.miff
convert $infile2 -colorspace gray 1tmp2.miff
qrange2=`convert xc: -format "%[fx:quantumrange*quantumrange]" info:`
m1=`convert 1tmp1.miff -format "%[mean]" info:`
m2=`convert 1tmp2.miff -format "%[mean]" info:`
m12=`convert xc: -format "%[fx:$m1*$m2]" info:`
s1=`convert 1tmp1.miff -format "%[standard-deviation]" info:`
s2=`convert 1tmp2.miff -format "%[standard-deviation]" info:`
s12=`convert xc: -format "%[fx:($qrange2)/($s1*$s2)]" info:`
imh convert \( 1tmp1.miff -evaluate subtract $m1 \) \( 1tmp2.miff -evaluate subtract $m2 \) \
-compose multiply -composite -evaluate multiply $s12 \
+write ncc.png -format "%[mean] (%[fx:mean])\n" info:
65535.6 (1.00001)
Note that we have to multiply the result by quantumrange^2. One quantumrange is need to compensate for IM normalizing to the range 0 to 1 before multiplying and unnormalizing the result by multply by quantumrange
(5/quantumrange)*(5/quantumrange)*quantumrange = 25/quantumrange and we need 25.
The other quantumrange in the square is needed because the ncc result in in the range -1 to 1. Thus to get the result of perfect match to be 65535 (1), we must multiply the 1 by quantumrange for the non-normalized result.
Last edited by fmw42 on 2013-08-19T17:23:32-07:00, edited 11 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: V7 compare
I used RMSE as an example of how the mask might work.
Perhaps all the metrics can be achieved within a single convert, and the compare command is strictly redundant. Even if it is, incorporating it into the convert/magick command makes sense to me.
Perhaps all the metrics can be achieved within a single convert, and the compare command is strictly redundant. Even if it is, incorporating it into the convert/magick command makes sense to me.
snibgo's IM pages: im.snibgo.com
Re: V7 compare
Grab ImageMagick 6.8.6-9 beta tomorrow afternoon and try
- convert image.png reference.png -metric RMSE -compare -format "%[distortion]" info:
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
magick wrote:Grab ImageMagick 6.8.6-9 beta tomorrow afternoon and try
- convert image.png reference.png -metric RMSE -compare -format "%[distortion]" info:
What about the output image? It would be nice to get the rmse resulting image as well as the statistics.
The above looks pretty much like
convert image image2 -compose rmse -composite rmseresult
with an output statistic, ie.
convert image image2 -compose rmse -composite -format %[mean] (%[fx:mean])" info:
I suppose you created a new function because you did not want to change -compose to add statistics, which makes sense. But seems one could get the same by just creating a new compose format, rmse
convert image image2 -compose rmse -composite -write resultimge -format "%[mean] (%[fx:mean])\n" info:
or
convert image image2 -compose rmse -composite -format "%[mean] (%[fx:mean])\n" -write info: resultimage
Either way, it would be nice at some later time to add more (compare) metrics to this as options (whichever ones have 0 to 1 limits), if you have not already done so. So -metric ncc might be a possible future metric, since it is also a metric of compare in range 0 to 1.
Re: V7 compare
The difference image is returned by -compare and -metric supports all the standard metrics including NCC.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
magick wrote:The difference image is returned by -compare and -metric supports all the standard metrics including NCC.
Great! Thanks.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
magick wrote:Grab ImageMagick 6.8.6-9 beta tomorrow afternoon and try
- convert image.png reference.png -metric RMSE -compare -format "%[distortion]" info:
The above works fine. Also one can do the following to get the difference image.
convert image.png reference.png -metric RMSE -compare difference.png
But then it does not output the metric value.
So it seems to me that the -format "%[distortion]" info: might not really be necessary. If one made this work like compare and always output the metric value to the terminal. For example, if you only wanted the metric returned, one could then just do
convert image.png reference.png -metric RMSE -compare null:
in analogy to
compare -metric RMSE image.png reference.png null:
Am I missing something such that it needs to work with -format "%[distortion]" info:? Was there something that user snibgo requested that I am missing? Or is this just due to the difference between how compare is coded vs how convert needs to do the same thing?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
This seems to work fine in IM 6.8.6.9 Q16 Mac OSX, but it would be nice if it would respect the -precision argument
convert -precision 5 rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]\n" info:
0.10396026946004832681
convert rose: \( rose: -blur 0x3 \) -precision 5 -metric RMSE -compare -format "%[distortion]\n" info:
0.10396026946004832681
convert rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]\n" -precision 5 info:
0.10396026946004832681
Work Around:
printf "%1.5f\n" $(convert rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]" info:)
0.10396
convert -precision 5 rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]\n" info:
0.10396026946004832681
convert rose: \( rose: -blur 0x3 \) -precision 5 -metric RMSE -compare -format "%[distortion]\n" info:
0.10396026946004832681
convert rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]\n" -precision 5 info:
0.10396026946004832681
Work Around:
printf "%1.5f\n" $(convert rose: \( rose: -blur 0x3 \) -metric RMSE -compare -format "%[distortion]" info:)
0.10396
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: V7 compare
v6.8.7 under Windows 7: it does now respect "-precision", provided this is before "-format":
Code: Select all
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert -precision 5 rose: ( rose: -blur 0x3 ) -metric RMSE -compare -format "%[distortion]\n" info:
0.10396
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert rose: ( rose: -blur 0x3 ) -precision 5 -metric RMSE -compare -format "%[distortion]\n" info:
0.10396
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert rose: ( rose: -blur 0x3 ) -metric RMSE -compare -format "%[distortion]\n" -precision 5 info:
0.10396
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert -precision 10 rose: ( rose: -blur 0x3 ) -metric RMSE -compare -format "%[distortion]\n" info:
0.1039602695
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert rose: ( rose: -blur 0x3 ) -precision 10 -metric RMSE -compare -format "%[distortion]\n" info:
0.1039602695
D:\web\im>c:\im\ImageMagick-6.8.7-Q16\convert rose: ( rose: -blur 0x3 ) -metric RMSE -compare -format "%[distortion]\n" -precision 10 info:
0.10396
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: V7 compare
It has been working in IM since 6.8.6.10. Changes in general are folded into IM 7 as well.
And true as far as I understand that the -precision must be before -format.
And true as far as I understand that the -precision must be before -format.