Re: Compare two images and get the difference
Posted: 2012-04-16T17:25:50-07:00
I think I really need to see your images to figure out what is going on.lusky wrote:How many graylevels are? How much must the pixel change that the program count it. Like I sayd the number is 1,2%? If it grayscale it just for 1 level, how much must it be to count it?
I think it gets changed for 1 graylevel in any rgb channel. If you are in Q16 IM that is 1 out of 65535 for any of red, green or blue channels. If you are on Q8 IM then 1 out of 256.
Please read and see the examples at http://www.imagemagick.org/Usage/compare/#compare. Even the difference between a png and jpg version of the image will see the difference.
See the comment there also:
Note however that this mask is of ANY difference, even the smallest difference. For example you can see all the minor differences that saving an image to the Lossy JPEG Format produces...
You can also make the difference image show just red and white as per the example there
compare bag_frame1.gif bag_frame2.gif \
-compose Src compare_src.gif
However, you can add -fuzz XX% to the compare. It will not change the statistics, but the diffimage will only show differences larger than that fuzz factor. -fuzz measures the rmse color distance between two colors and is therefore consistent with the -metric rmse.
Try this:
convert rose: rose.jpg
compare -metric rmse rose: rose.jpg -compose src rose_diff.png
1769.16 (0.0269957)
compare -fuzz 5% -metric rmse rose: rose.jpg -compose src rose_diff5.png
1769.16 (0.0269957)
In the first case, almost every pixel is red as there is some difference between png and jpg due to compression, even if only 1 graylevel
In the second case, much of the image is white, because it only considers coloring red where the two images have pixels that are more than 5% different in color.
If you need the statistics to show the true difference after the fuzz processing, then you need to process the output
compare -fuzz 5% -metric rmse rose: rose.jpg -compose Src -highlight-color White -lowlight-color Black rose_diff5bw.png
convert rose_diff5bw.png -format "%[fx:mean]" info:
0.0540372
This produces a b/w diffimage. Thus 5.4% are white and the rest black. So 5.4% of the pixels have changed. Those are the ones that are more than 5% fuzz factor different in color. Note that 5.4% is count and 5% is rmse color difference, i.e. not count.