Histogram with huge file size...

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Histogram with huge file size...

Post 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?
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Histogram with huge file size...

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Histogram with huge file size...

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Histogram with huge file size...

Post 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
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Histogram with huge file size...

Post by rnbc »

Nice, now is there someway to make it run faster without -filter Point -resize 50% or similar extreme measures?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Histogram with huge file size...

Post 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.
rnbc
Posts: 109
Joined: 2010-04-11T18:27:46-07:00
Authentication code: 8675308

Re: Histogram with huge file size...

Post by rnbc »

Thanks guys, once again! :-D
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Histogram with huge file size...

Post 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:

Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply