Page 1 of 1

Unable to parse identify output

Posted: 2012-11-11T22:36:52-07:00
by happycloud
We are using the NodeJS imagemagick module and need to parse the dump of identify. Recently, I think, the output of identify has broken the node modules (there are a few and they all broke) because the dump is not parseable. I have tested this with IM 6.7.7-6 and multiple images (mostly pngs seem to be at issue - but not consistent).

Here's the problematic section of the ouptut

Code: Select all

 Image statistics:',
    Overall:',
      min: 52 (0.203922)',
      max: 255 (1)',
      mean: 197.2 (0.773333)',
      standard deviation: 70.187 (0.275243)',
      kurtosis: -0.83089',
      skewness: -0.803467',
  Colors: 123',
  Histogram:',
       973: (107,108, 52) #6B6C34 srgb(107,108,52)',
        70: (108,105, 55) #6C6937 srgb(108,105,55)',
         2: (110,107, 58) #6E6B3A srgb(110,107,58)',
         2: (112,109, 60) #706D3C srgb(112,109,60)',
         .... more here
  Colormap: 129',
      0: (107,108, 52) #6B6C34 srgb(107,108,52)',
      1: (232,232,208) #E8E8D0 srgb(232,232,208)',
      2: (167,178, 80) #A7B250 srgb(167,178,80)',
      3: (166,164,134) #A6A486 srgb(166,164,134)',
      4: (114,111, 63) #726F3F srgb(114,111,63)',
      5: (209,210,161) #D1D2A1 srgb(209,210,161)',
      ... mohre here all the way to 128 in this case - 129 total
As you can see, this mostly reads like a multi depth array for all fields except the colormap - the "129" string effectively breaks this pattern - I assume the 0-128 fields belong to the colormap but in this file they do not - they belong as root entries. It's like the '129' string should not be there.

Suggestions?

Re: Unable to parse identify output

Posted: 2012-12-06T23:09:10-07:00
by anthony
I would say it is a valid point. Though you could parse the tree using the indent instead.

Do you have a specific identify part that you are interested in? I usually parse identify output for specific components by looking for the start tag, and exiting when indent is not right, or the next tag (though that can be fragile.

For example from IM Examples... Comparing images..
This gets min,max,average colors from a resulting grayscale image. Though it does go 1 line too far.

convert image1 image2 -compose Difference -composite \
-colorspace gray -verbose info: |\
sed -n '/statistics:/,/^ [^ ]/ p'

Re: Unable to parse identify output

Posted: 2012-12-07T11:58:45-07:00
by magick
The output of identify is meant to be "human readable." For the colormap entry, the number that follows is the number of entries in the colormap. However, this information is already available as the Colors tag. We'll remove the value to ensure a consistent format making it both human and machine readable.

Re: Unable to parse identify output

Posted: 2012-12-07T12:11:39-07:00
by fmw42
I am not sure that is a good idea? Is it possible that the number of entries in the colormap may be different from the number of colors?

Re: Unable to parse identify output

Posted: 2012-12-07T12:12:37-07:00
by magick
Right, we would need to present it as a separate tag.