Display histogram

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
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Display histogram

Post by Elapido »

Is able Imagemagick to display information about the levels of an image? What would be amazing is displaying a graphic histogram...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Display histogram

Post by fmw42 »

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

see also my unix bash script, histog, at the link below
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Re: Display histogram

Post by Elapido »

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

Re: Display histogram

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Re: Display histogram

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Display histogram

Post 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
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Re: Display histogram

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Display histogram

Post 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
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Re: Display histogram

Post 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.
Elapido
Posts: 42
Joined: 2011-06-10T14:27:28-07:00
Authentication code: 8675308

Re: Display histogram

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Display histogram

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Display histogram

Post 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)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply