Page 1 of 1

Display histogram

Posted: 2011-06-23T13:40:12-07:00
by Elapido
Is able Imagemagick to display information about the levels of an image? What would be amazing is displaying a graphic histogram...

Re: Display histogram

Posted: 2011-06-23T13:51:10-07:00
by fmw42
see http://www.imagemagick.org/Usage/files/#histogram

see also my unix bash script, histog, at the link below

Re: Display histogram

Posted: 2011-06-23T16:22:49-07:00
by Elapido
Great!

Re: Display histogram

Posted: 2011-06-23T20:39:52-07:00
by anthony
The "histogram" images comments contain the complete dump of the color counts in the image.
http://www.imagemagick.org/Usage/files/#histogram
If you don't want it you can tell IM to not generate that comment (and the time it takes to do this) using
-define histogram:unique-colors=false

Re: Display histogram

Posted: 2011-06-24T03:42:16-07:00
by Elapido
Can I generate the histogram and invert its colors or give it a blueish tone with just one command? I'm using this command as part of an AutoHotkey script:

runwait, %comspec% /c d:\Imagemagick\convert %imageo% -separate -append -define histogram:unique-colors=false histogram:histogram1o.jpg ,,hide

Re: Display histogram

Posted: 2011-06-24T10:41:27-07:00
by fmw42
You can do it with a pipe, e.g

convert rose: -separate -append -define histogram:unique-colors=false histogram:MIFF:- | convert - -negate histog.jpg

or with mpr (in memory image) as


convert \( rose: -separate -append -define histogram:unique-colors=false -write histogram:mpr:hist +delete \) \
mpr:hist -negate histog.jpg

see
http://www.imagemagick.org/Usage/files/#mpr

Re: Display histogram

Posted: 2011-06-24T13:14:10-07:00
by Elapido
It's working here :)

I don't want to bother you, but you could save me some time investigating how to:

-give it a blue tone
-save it as a png with partial transparency

Much appreciated.

Re: Display histogram

Posted: 2011-06-24T13:44:43-07:00
by fmw42
Elapido wrote:It's working here :)

I don't want to bother you, but you could save me some time investigating how to:

-give it a blue tone
-save it as a png with partial transparency

Much appreciated.

What part do you want blue -- the histogram or the background? What part do you want transparent -- the histogram or the background

try this


convert \( rose: -separate -append -define histogram:unique-colors=false -write histogram:mpr:hist +delete \) \
mpr:hist -negate -fill blue -opaque black -transparent white histog.png

see
http://www.imagemagick.org/Usage/color_basics/#replace

Re: Display histogram

Posted: 2011-06-24T13:59:48-07:00
by Elapido
I'll try although I think this is more than enough for what I need:

convert 1.jpg -separate -append -define histogram:unique-colors=false histogram:MIFF:- | convert - -fill "#ddddff" -colorize 60% histogram1e.jpg

Thanks man.

Re: Display histogram

Posted: 2011-06-24T14:20:44-07:00
by Elapido
The only problem I'm having with histograms is that the graphics are too flat in some images (when they have much contrast), almost unreadable sometimes. Notice the difference between the histogram in Photoshop (left) and Imagemagick (right) for the same image. There are cases in which you just see an almost empty square. I wonder if this can be fixed somehow.

Image

Re: Display histogram

Posted: 2011-06-24T14:28:19-07:00
by fmw42
post a link to your image

or try adding -scale 100x50%! -threshold 50% before the output

unfortunately right now IM has no scale control or clip if a bin is too high on the histogram graph that I know about other than what I have suggested above.

You could process the histogram to modify any tall peaks to half height and then scale the graph down as above.

Re: Display histogram

Posted: 2011-06-24T20:20:40-07:00
by anthony
Elapido wrote:Can I generate the histogram and invert its colors or give it a blueish tone with just one command?

YES the trick is to write the histogram output into a MPR: image store. Then read it back.
See MPR in IM Examples
http://www.imagemagick.org/Usage/files/#mpr

Here is one example that resizes the histogram result, using only one command..

Code: Select all

  convert rose: -define histogram:unique-colors=false \
          -write histogram:mpr:hgram  +delete \
          mpr:hgram  -strip  -resize 50%  histogram_resized.gif
In the future we will probably remove histogram: output in favour of in-memory histogram processing. But if done it will be a IM version 7 change (in pre-alpha development)