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?".
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Histograms in Photoshop CS6 vs. IM

Post by blue-j »

First, thanks so much to all the developers and community! IM is astounding, and your efforts are very sincerely appreciated.

I'm investigating the histogram displays in Photoshop CS6 (13.0.4) and comparing them with IM 6.8.0-2. Wow, PS is doing some unusual things! First, for the Colors option, Adobe's display scales the normal 256x200 IM output down 80%, then crops off the top, so it's 100px high. Any idea why they would do that? So odd! (And trust me, I am not assuming that Adobe's work is superior here).

Second, I cannot for the life of me get a histogram out of IM that resembles their "RGB" or composite histogram (or even their lumosity histogram). IM's is remarkably different. I am trying this:

Code: Select all

convert input_file.jpg -separate -append -define histogram:unique-colors=false -write histogram:mpr:hgram +delete mpr:hgram -strip output_file.gif
Anyone have a notion of where the differences come from?

Here are the files and histograms (zip) for comparison:
http://bit.ly/1aF59jA

Thanks so much for your time in considering this!!
J
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 »

The photoshop color histogram looks quite like the IM histogram except for the fact that PS crops it. I have no idea why unless they want to amplify the small counts. The main difference is that when IM overlays each color, it is done additively so that red+green+blue look white. PS appears to replace the white with mid gray.

With regard to the grayscale histogram that could be a color space issue, depending upon what version of IM you are using. You do not say what command you used to make it grayscale.

try

convert image -set colorspace RGB -colorspace gray -define histogram:unique-colors=false histogram:grayscale_histogram.gif

Or just use

convert image -modulate 100,0,100 define histogram:unique-colors=false histogram:grayscale_histogram.gif


In your version of IM -grayscale converted the image to linear grayscale with gamma=1 and you probably need a non-linear grayscale with gamma=0.4545 to match PS
Last edited by fmw42 on 2013-05-30T14:21:00-07:00, edited 2 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 »

I don't know PS so can't comment on that.

Two points about IM histograms:

1. I like to add a black border, otherwise a peak at either end can get lost when a viewer displays against a white background.

2. For grayscale intensity, different methods of conversions to gray can yield very different results. Eg (IM 6.8.5-0 on Windows 7):

Code: Select all

convert rose: -grayscale Lightness histogram:- | convert - -bordercolor Black -border 1 h1.png

convert rose: -grayscale Brightness histogram:- | convert - -bordercolor Black -border 1 h2.png
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 »

I do not think that -grayscale was available at 6.8.0.2, but I could be mistaken.
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 »

Ah, that's true. It was introduced for 6.8.5.
snibgo's IM pages: im.snibgo.com
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

I'm very appreciative of your help!

I am not converting the image to grayscale. I was following the counsel and copying the code from here:

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

starting "On the other hand a better 'global' histogram can be generated by simply separating all the color channels in the original image and appeneding. The resulting histogram is a representation of all the color values regarless [sic] of which channel that value is from."

but perhaps this was assuming the image was converted to grayscale beforehand? Sounds like it?

Attempting to follow your counsel, I tried:

Code: Select all

convert input_file.jpg -set colorspace RGB -grayscale -define histogram:unique-colors=false -write histogram:mpr:hgram +delete mpr:hgram -strip output_file.gif

Code: Select all

convert input_file.jpg -set colorspace RGB - grayscale -gamma 0.45455 -define histogram:unique-colors=false -write histogram:mpr:hgram +delete mpr:hgram -strip output_file.gif

Code: Select all

convert input_file.jpg -modulate 0,100,0 -define histogram:unique-colors=false -write histogram:mpr:hgram +delete mpr:hgram -strip output_file.gif

Code: Select all

convert input_file.jpg -smodulate 0,100,0 -gamma 0.45455 -define histogram:unique-colors=false -write histogram:mpr:hgram +delete mpr:hgram -strip output_file.gif
None had the same result. I apologize in advance if I misapplied your advice, and thank you again for your time in investigating this matter!

J
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

snibgo wrote:Ah, that's true. It was introduced for 6.8.5.
Does this mean that I must upgrade to =>6.8.5 in order to test your proposed code using the -grayscale switch?

Thanks again,
J
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 »

1. Note that "-separate" is a greyscale operation (it separates a colour image into 3 greyscale images). It gives different results in 6.8.4 and 6.8.5. I generally suggest that people who use greyscale upgrade to 6.8.5.

2. Your "-modulate 0,100,0" is very different to Fred's suggestion: "-modulate 100,0,100".
snibgo's IM pages: im.snibgo.com
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

snibgo wrote:1. Note that "-separate" is a greyscale operation (it separates a colour image into 3 greyscale images). It gives different results in 6.8.4 and 6.8.5. I generally suggest that people who use greyscale upgrade to 6.8.5.

2. Your "-modulate 0,100,0" is very different to Fred's suggestion: "-modulate 100,0,100".
I will try to upgrade. I had trouble last time I tried as a dependency failed to build using Macports.

I mistyped. I in fact did try 100,0,100 (desating the image).

Peace,
J
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

snibgo wrote:I don't know PS so can't comment on that.
I understand! I did however provide the PS histograms, in case you are curious about what they are displaying.

Thanks again!
J
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 are lots of ways in IM to convert to grayscale. I have no idea what PS is using. The most common ones are convert to rec601luma, demodulate (in various colorspace), average the channels. Each one can be done in a linear or non-linear manner.

Just doing the obvious in IM 6.8.5.8 (which does not need the -set colorspace RGB),

convert PhotoBoothXmas_0109.JPG -colorspace gray -define histogram:unique-colors=false histogram:hist3.png

Image

If I open your image in my old PS CS and convert to grayscale and look at the histogram, I get the following. Except for the scaling, it looks similar to mine above.

Image


The above is a bit different from demodulating

convert PhotoBoothXmas_0109.JPG -modulate 100,0,100 -define histogram:unique-colors=false histogram:hist10.png

Image


Colorspace profiles may also affect the result. PS may override the colorspace in the image with its own if you have not set up the Color Settings panel appropriately.
Last edited by fmw42 on 2013-05-30T16:41:26-07:00, edited 1 time in total.
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

What you've shown looks very similar to the "Luminosity" histogram when you are in RGB mode (not converting to Grayscale) in CS6 (yet again, PS crops the top off). It also does look like the composite histogram in PS after converting to Grayscale.

The "RGB" composite histogram looks meaningfully different (the one I posted). I suspect something other than converting to grayscale first may be at work there? I'm curious.

Thanks so much again! Sorry to strain your patience. I am not a person who thinks that it's ideal to match PS, but this is a learning experience for me to understand more about histograms and what PS and IM are representing with them.

- 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 »

I don't use Photoshop often nor have access to test at the moment, but I do have two ideas. First, Photoshop uses an approximation for generating image statistics. In a GUI environment where the histogram window may always be showing, this is a practical necessity for processor load. This approximating may cause your height clipping. There was some way to force an update when needed. Second, to fmw42's idea of amplifying small counts, Photoshop does have a logarithm scaled histogram mode. Your histograms didn't look log scaled though.

I agree that looking into different or unexpected results often leads to a deeper understanding.
blue-j
Posts: 68
Joined: 2007-06-12T14:03:18-07:00

Re: Histograms in Photoshop CS6 vs. IM

Post by blue-j »

GreenKoopa wrote:I don't use Photoshop often nor have access to test at the moment, but I do have two ideas. First, Photoshop uses an approximation for generating image statistics. In a GUI environment where the histogram window may always be showing, this is a practical necessity for processor load. This approximating may cause your height clipping. There was some way to force an update when needed.
Yes, PS offers the ability to build a histogram based on cached image data rather than the actual original data in order to speed up results, but the differences between the two modes don't account for discrepancies we've reported in this thread. It's not related to the cropping. I think that Adobe decided those outliers don't have practical value to the user, and that's why they are truncated. Not sure. I'm not going to crop them out.

Basically, Fred has presented the solution for mirroring PS's "luminosity" histograms, it seems, but we don't yet know what they are doing to present their "RGB" or composite histograms. (I have yet to test individual channel histograms). I'm waiting a bit for ImageMagick to update to 6.8.5-5 so version is not a factor...

- J
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 »

I might add that Gimp's "value" histogram of the image is similar (but not identical) to PS's and IM's.
snibgo's IM pages: im.snibgo.com
Post Reply