Histograms in Photoshop CS6 vs. IM

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

Re: Histograms in Photoshop CS6 vs. IM

Post by fmw42 »

There is one other way to do the histogram. That is to separate each channel, append and get the histogram from all channel data together. A global sort of histogram. This seems to be what PS is doing. That is probably what they mean by RGB composite


convert PhotoBoothXmas_0109.JPG -separate +append -define histogram:unique-colors=false histogram:hist6.png

Image

Your result from PS


Image

Prior to IM 6.8.5.0 you would need to add -set colorspace RGB before the -separate.



It is odd to me that this is not the same or equivalent to averaging the channels by

convert PhotoBoothXmas_0109.JPG -separate -evaluate-sequence mean -define histogram:unique-colors=false histogram:hist7.png

Image

which is the same as

convert PhotoBoothXmas_0109.JPG -colorspace OHTA -channel R -separate +channel -define histogram:unique-colors=false histogram:hist8.png

Image

Aside: In my redist script, the global histogram is one of many options that can be used.
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

Yes! I came upon the same result and came to post it when I saw yours. The only thing is a type. I believe you intended to write

Code: Select all

convert PhotoBoothXmas_0109.JPG -separate -append -define histogram:unique-colors=false histogram:hist6.png
with a "-" before append, yes?

That is indeed the RGB histogram shown by PS. The other one, converting to gray first, is equivalent to the "Luminosity" histogram in PS.

Victory! Big thanks to all! I would buy you a drink if I could.

Appending is not the same as averaging. When you append, only the highest value is shown, hiding the lower values. When you average, you show the mean

That begs another question, which is, why would users want to see only a composites of the highest values, rather than the means of the values?

- J
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Histograms in Photoshop CS6 vs. IM

Post by GreenKoopa »

-append joins top-to-bottom, +append joins left-to-right. Since all you want is the histogram, it doesn't matter.
blue-j wrote:When you append, only the highest value is shown, hiding the lower values.
When you append, won't all values (every channel of every pixel) show in the histogram?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Histograms in Photoshop CS6 vs. IM

Post by fmw42 »

Appending is not the same as averaging. When you append, only the highest value is shown, hiding the lower values. When you average, you show the mean
I agree with GreenKoopa. Appending is not just showing the larger value. It is showing the histogram all the values R+G+B whereas averaging is getting the histogram of the averaged channels or (R+G+B)/3. Thus a scale factor of 3 or 1/3. The only difference might be (?) clipping if the sum is done and goes above 16 bits before the divide by 3. But I thought IM does all the processing in double precision floats. So I do not understand why it might clip.


Again, same as GreenKoopa. I used +append to append the images horizontally. But you would get the same result in this case of doing the histogram using -append to append the images vertically.
That is indeed the RGB histogram shown by PS. The other one, converting to gray first, is equivalent to the "Luminosity" histogram in PS.
It kind of makes sense from the names. RGB combined means get the data from all the channels and make the histogram. Luminosity histogram means get the histogram from the luminosity channel Y=rec601luma. Y is from YUV, YIQ, YCbCr, etc., which is the same as colorspace gray. see http://www.imagemagick.org/script/comma ... colorspace
Last edited by fmw42 on 2013-05-31T15:31:59-07:00, edited 3 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Histograms in Photoshop CS6 vs. IM

Post by snibgo »

When you append, won't all values (every channel of every pixel) show in the histogram?
Yes. Averaging is a primitive form of greyscale conversion. Appending uses the actual values of each channel. The difference can be readily seen:

Code: Select all

convert xc:red xc:lime xc:blue -append test.png

convert test.png -separate -append -define histogram:unique-colors=false histogram:h3.png
convert test.png -separate -evaluate-sequence mean -define histogram:unique-colors=false histogram:h4.png
This is significant when, for example, we want to avoid clipping during further processing.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Histograms in Photoshop CS6 vs. IM

Post by fmw42 »

That is a good example, snibgo. It would appear that it is a matter of putting the data into different bins rather than a clipping issue as I was just about to suggest. But your example makes it much clearer.

With the average here, you get 3 values of (255+0+0)/3 from rgb(255,0,0), rgb(0,255,0) and rgb(0,0,255). With all the channels you get 3 white (255) and 6 black (0) values. Great example.

Note the average (or mean) can also be obtained from the first channel of OHTA, which is not the same as colorspace gray. Colorspace gray is the same as luminosity, Y.

But your use of -separate -append and -separate -evaluate-sequence mean makes if very clear.

see also http://www.imagemagick.org/script/comma ... colorspace
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

Thanks so much for sharing your knowledge. This has been very informative for me! I enjoy learning about imaging a lot and appreciate this community and the mentorship you all give me. Thanks again!

J
Post Reply