Page 1 of 1

Histogram from mono compare output

Posted: 2012-04-22T17:40:12-07:00
by jash
I am comparing two images using

Code: Select all

compare -metric AE -fuzz 35%  f1.jpg f2.jpg  -highlight-color white -lowlight-color black -compose src im_compare.jpg
This works great when I look at the output, but I want to read the value of the difference into a program by counting the number of white pixels / calculating ratio of white to black.

When I get the histogram of the compare output file, it isn't pure black and white. There are a number of nearly black and nearly white pixels:

Code: Select all

     38325: (  0,  0,  0) #000000 black
      1169: (  1,  1,  1) #010101 rgb(1,1,1)
       763: (  2,  2,  2) #020202 rgb(2,2,2)
       395: (  3,  3,  3) #030303 grey1
       139: (  4,  4,  4) #040404 rgb(4,4,4)
        62: (  5,  5,  5) #050505 grey2
        21: (  6,  6,  6) #060606 rgb(6,6,6)
         5: (  7,  7,  7) #070707 rgb(7,7,7)
         1: (248,248,248) #F8F8F8 rgb(248,248,248)
         4: (249,249,249) #F9F9F9 rgb(249,249,249)
        29: (250,250,250) #FAFAFA grey98
        63: (251,251,251) #FBFBFB rgb(251,251,251)
       143: (252,252,252) #FCFCFC grey99
       324: (253,253,253) #FDFDFD rgb(253,253,253)
       551: (254,254,254) #FEFEFE rgb(254,254,254)
      2006: (255,255,255) #FFFFFF white
I've tried using -threshold, -black-threshold, -contrast-stretch, -fill, but I can't convert it to be just black and white.

Is there something I've done in the compare function that makes it impossible to reduce to B&W? Or is that correct and I should do a second conversion to get to B&W - if so, how?
Thanks.

Re: Histogram from mono compare output

Posted: 2012-04-22T18:33:57-07:00
by fmw42
set the -metric to AE and the result will be binary black and white only and the result will be the count of white pixels. You can get the total count from the widthxheight and then the number of black from widthxheight - number of white.


From the example at http://www.imagemagick.org/Usage/compare/#compare, modified to add -metric AE


compare -metric AE bag_frame1.gif bag_frame2.gif \
-compose Src -highlight-color White -lowlight-color Black \
compare_mask.gif

The above works on IM 6.7.6.7 Q16 Mac OSX Snow Leopard. You do not say what version of IM and platform you are using!

Re: Histogram from mono compare output

Posted: 2012-04-22T19:28:17-07:00
by jash
Hi Fred, Thanks for the quick reply.
I'm using ImageMagick 6.6.0-4 2011-06-15 Q16 on Lubuntu 11.10.

Removing the fuzz gives an almost completely white image:

Code: Select all

        18: (  0,  0,  0) #000000 black
         4: (  1,  1,  1) #010101 rgb(1,1,1)
         5: (  2,  2,  2) #020202 rgb(2,2,2)
         2: (  3,  3,  3) #030303 grey1
         4: (249,249,249) #F9F9F9 rgb(249,249,249)
        19: (250,250,250) #FAFAFA grey98
        27: (251,251,251) #FBFBFB rgb(251,251,251)
        79: (252,252,252) #FCFCFC grey99
       173: (253,253,253) #FDFDFD rgb(253,253,253)
       261: (254,254,254) #FEFEFE rgb(254,254,254)
     43408: (255,255,255) #FFFFFF white

I played with the fuzz factor for a while so it accurately highlighted the change I want to measure. If I keep the fuzz factor, how could I convert all pixels that are #070707 or less to black and all that are #F8F8F8 or higher to white?

Re: Histogram from mono compare output

Posted: 2012-04-22T19:32:37-07:00
by fmw42
This works fine for me in the current release even using -fuzz. I only get black and white in the histogram.


compare -metric AE -fuzz 35% bag_frame1.gif bag_frame2.gif \
-compose Src -highlight-color White -lowlight-color Black \
compare_mask_f35.gif


I think you will have to upgrade your IM version.