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?
Histogram with huge file size...
Re: Histogram with huge file size...
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?
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?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Histogram with huge file size...
"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.
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.
snibgo's IM pages: im.snibgo.com
Re: Histogram with huge file size...
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...
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...
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...
Thanks guys, once again! 

- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Histogram with huge file size...
Okay I get it.
Adding -define histogram:unique-colors=false to a command like turn off histogram comment generation.
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:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/