Skip to main content
Known Participant
March 6, 2011
Question

Is the number of histogram pixels the same for each channel within each layer?

  • March 6, 2011
  • 2 replies
  • 868 views

Dear Photoshop Scripting Forum:

I have written a script to isolate the number histogram pixels for each channel within each layer of a file.

However, I have found some unexpected results: That, the number of pixels is the same for each channel within each layer.

For example,

  Layer 1 has 18,979 pixels by itself, and so does each channel within it (Red, Green, and Blue)

  Layer 1, Channel Red, has 18,979 pixels

  Layer 1, Channel Green, has 18,979 pixels

  Layer 1, Channel Blue, has 18,979 pixels.

This does not seem right to me.

Does someone else have the same experience, or knowledge of something else?

I am wondering if there is a bug in my script.

If need be, I will post the script, but it's kind of long for a forum.

Thank you.

This topic has been closed for replies.

2 replies

c.pfaffenbichler
Community Expert
Community Expert
March 6, 2011

Like Michael explained …

The Histogram is an Array of integers, so if you want to assess the number of pixels of a certain value (like the number of pixels that are white, i.e. 255) you’ll have to address that element of the histogram.

Known Participant
March 6, 2011

cpfaffenbichler:

Thank you for your reply.

When you associate "white" with "255", are you saying that the 255th element of the Histogram array is the "white" intensity value?

If so, I guess the 0th element would be the "black" intensity value.

This is very interesting to me.

I would like to understand the Histogram in more detail.

Is there any documentation you would recommend?

:redthroughviolet

Inspiring
March 6, 2011

It is not a bug. The channels are just a way of holding color information about the pixel. The number of channels and what 'color' that channel represents depends on the color mode of the image. For any given mode each channel will have the same number of pixels because it is all the channels( component ) combined in an image that hold the color information about the pixels.

Known Participant
March 6, 2011

Michael L Hale:

Thank you for your reply.

It is very helpful to know that I might be on the right track!

Yes, the channels hold color information, but why would each color channel have the same number of pixels?

If you have a layer with no red, and you look at the red channel, shouldn't there be 0 pixels in its Histogram?

It may be that I need to start a study of Channels and their Histograms.

The Help in PS3 Extended is OK, but does not go very deep.

Thank you for your help.

:Susan T. Sailow

Inspiring
March 6, 2011

The following is for RGB 8bit images.

The red historgram is an array of red values of the pixels that range from 0 to 255. Each element in the array has the number of pixels that have that red value. So for example if you had a layer that is pure red 255,0,0 all the pixels would be in the 255 element and there would be no pixels in the other elements. The red historgam still has the same number of pixels as the layer. They are just all in one histogram element( they all have the same value ).

But even if you know that all the pixels in a layer are all in the last element(255) of the red histogram you still don't know the color of the pixels. A white pixel has a red value of 255. So does a yellow, magenta, etc pixel. If you only know the red value of a pixel the pixel could be one of over 65000 colors. Most of which would not be considerd 'red'

It is the three channels together that detemine a pixel's color. Unless the layer is one color you can not tell the color of the pixels from looking at the histogram.

Unless you use the color range selection then get the histogram of the selection. Even then you need to decide what color value make up 'red'