Page 1 of 1

getting all histograms of tiles in one convert

Posted: 2011-02-11T07:55:46-07:00
by nicslos
Hello,
I need to differentiate between the back- and foreground of images to get the most common colors of the centered foreground
neglecting colors at the outer regions if the image.
For this, I need the histogram of each tile in an image. I'm tiling the image in 5x5 subimages and generating the histograms.
Its easy to do in two convert commands.

convert -map netscape: input_image.jpg +gravity -crop 20%x20% input_image_%d.jpg
convert input_image_?.jpg -format "<file>%f</file>\n<histogram>%c</histogram>" histogram:info:-

This generates me a structures output that like

<file>input_image_1.jpg</file>
<histogram>
561: (102, 0, 51) #660033 rgb(102,0,51)
1: (102, 0,102) #660066 rgb(102,0,102)
...
</histogram>
...

Now I want to do the same in one run to avoid the tile files and because I need to spawn processes, and this is quite costy.
I tried:
convert -map netscape: input_image.jpg -crop 21%x21% -format "<tile>%c</tile>" histogram:info:-

Now I'm loosing the information about, which tile which histogram but just rely, that histograms are in the same order as they use to be with the
2 convert method.
is there a way to number or enumerate the histograms appropriately?
Or is there another way to do so?
thanks
nicslos

Re: getting all histograms of tiles in one convert

Posted: 2011-02-11T15:52:45-07:00
by fmw42
This seems to work by itself to identify the page, but the page number is always 1 when you add in the histogram: before info:


convert zelda3.png +gravity -crop 50%x50% -format "<file>%t_%p.%e</file>\n<histogram>%c</histogram>" info:

<file>zelda3_1.png</file>
<histogram></histogram>
<file>zelda3_2.png</file>
<histogram></histogram>
<file>zelda3_3.png</file>
<histogram></histogram>
<file>zelda3_4.png</file>
<histogram></histogram>


Perhaps Anthony can supply a solution.

Re: getting all histograms of tiles in one convert

Posted: 2011-02-12T00:19:10-07:00
by anthony
The %c is to print the image comment.
You see no result as the 'zelda' image contains no comment meta-data!

A histogram: generated image contains a comment that lists the histogram as plain text.
Unfortunately it is purly a output image coder. Which means you have to -write the image somewhere to generate any histogram (and its comment). However you can write the image to a mpr: memory register instead of disk, then read the image (and its comment) from that register.

See Histogram
http://www.imagemagick.org/Usage/files/#histogram
And specifically the "mpr:" coder in the very next section...

Code: Select all

  convert rose: -write histogram:mpr:hgram  +delete \
          mpr:hgram  -format '<histogram>\n%c</histogram>'  info:
NOTE the histogram comment can be HUGE and time consuming to generate. The previous example generated 3021 lines! This is why a special 'define' can be set to turn off its generation.

Eventually I would like to see a -histogram option that generates an image that other options can -graph or generate profiles from in various ways :-) But that these options are for in the future.