Page 1 of 1
Histogram with huge file size...
Posted: 2010-04-15T16:55:15-07:00
by rnbc
Hi!
When I generate a histogram for an image with a command like:
convert xpto.jpg histogram:output.png
The output.png file tends to be huge, something like 300k or more...
Now, if I do this:
convert xpto.jpg histogram:- | convert - output.png
The same exact histogram is generated (of course!) but now the file size is only about 2KB as expected.
Am I doing something wrong here?
Re: Histogram with huge file size...
Posted: 2010-04-15T17:53:36-07:00
by rnbc
Found the answer myself: the image contains, in comments, the entire list of colors with the color count for each one!
The correct way to sort this out in a single "convert" is something like this:
convert input.jpg -write histogram:mpr:xpto +delete mpr:xpto -strip -evaluate Divide 2 -evaluate Add 25% output.png
One trouble I'm still having is calculation time... damn it, 2.8 seconds in a 1.8GHz CPU for calculating an histogram of a 480*320 image?!? This is SLOW! Any ideas?
Re: Histogram with huge file size...
Posted: 2010-04-15T18:08:06-07:00
by snibgo
"identify -verbose" shows output.png from the first command carries a huge comment, which seems to be the numbers behind the graph, a written form of the histogram.
output.png also has a comment, but now it seems to be the histogram of the histogram image, which is (of course) much simpler.
I would expect "-strip" in the first command to remove that comment. Strangely, it doesn't.
Re: Histogram with huge file size...
Posted: 2010-04-15T18:19:56-07:00
by magick
Add
+set comment on the command line to remove a comment from an image, for example:
- convert image.png +set comment image.jpg
Re: Histogram with huge file size...
Posted: 2010-04-15T18:54:59-07:00
by rnbc
Nice, now is there someway to make it run faster without -filter Point -resize 50% or similar extreme measures?
Re: Histogram with huge file size...
Posted: 2010-04-16T05:38:15-07:00
by magick
The algorithm spends most of its time generating the histogram comment. We'll make it an option in ImageMagick 6.6.1-4 Beta by sometime tomorrow. Add -define histogram:unique-colors=true to generate the unique colors comment. Without it, generating a histogram is lightning fast.
Re: Histogram with huge file size...
Posted: 2010-04-20T15:01:03-07:00
by rnbc
Thanks guys, once again!

Re: Histogram with huge file size...
Posted: 2010-04-21T23:08:43-07:00
by anthony
Okay I get it.
Adding -define histogram:unique-colors=false to a command like turn off histogram comment generation.
Code: Select all
convert tree.gif -format %c histogram:info:
16: ( 0,128, 0) #008000 green
422: ( 0,255,255) #00FFFF cyan
126: ( 46,139, 87) #2E8B57 SeaGreen
381: ( 50,205, 50) #32CD32 LimeGreen
59: (160, 82, 45) #A0522D sienna
20: (255,255, 0) #FFFF00 yellow
Code: Select all
convert tree.gif -define histogram:unique-colors=false -format %c histogram:info: