22

I am trying to learn opencv but its very confusing. Can someone know the difference between imagedepth and the no. of channels in an image. Suppose the image depth is 8 and no. of channels R,G,B is 3. Then , what does it signify, I am having difficulty visualizing the 3d structure

leonidus
  • 363
  • 1
  • 3
  • 11

5 Answers5

27

The depth (or better color depth) is the number of bits used to represent a color value. I am not really into OpenCV, but a color depth of 8 usually means 8-bits per channel (so you have 256 color values - or better: shades of grey (see comment) - per channel - from 0 to 255) and 3 channels mean then one pixel value is composed of 3*8=24 bits.

However, this also depends on nomenclature. Usually you will say

"Color depth is 8-bits per channel"

but you also could say

"The color depth of the image is 32-bits"

and then mean 8 bits per RGBA channel or

"The image has a color depth of 24-bits"

and mean 8-bits per R,G and B channels.

Bottom-line: Documentation (or wording) has to be quite specific here ;-)

cli_hlt
  • 7,072
  • 2
  • 26
  • 22
10

Take it this way.

You have an image that has just a single pixel in it. The SIZE of the image is 1x1 pixels.

  • If this is a gray scale image, than only a SINGLE channel is required to represent the image. How? Because a gray image (assuming a 8-bit image) would have 8 bits that is 2 raised to the power 8 whjch is 256 different SHADES. From Black to White. Gray scale
  • Gray scale is generally the black and white image.
  • Now if the same single pixel image is made of colors, then we need three channels, namely Red,Green and Blue or RGB. When we mix the shades of these channels we get different colors.
  • Like, (255,255,255) is pure white in RGB and (0,0,0) is pure black
  • So now each channel will have shades from 0-255 that is 8-bits.
  • The resulting color image has a depth of 8-bits and number of channels being 3.
  • You can have more than 8 bits per channel, this increases the color ranges (shades)
  • For the 1x1 pixel image, the pixel color values will range from 0-255 per channel. That is [0 to 255 in R][0 to 255 in G][0 to 255 in B]
9

According to OpenCV documentation, in OpenCV depth is defined as the bit-depth of an individual channel. So if you have 8 bit depth and 3 channels, it means you have 24 bits per image pixel

CharlesB
  • 86,532
  • 28
  • 194
  • 218
6

Image depth means the range of value each channel can have. If you have a channel depth of e.g. 8 bit (unsigned char) one channel can have values from 0 - 255. RGB means 3 channels, one for the R ed value, one for one for the G reen value and one for the B lue value.

Stephan Dollberg
  • 32,985
  • 16
  • 81
  • 107
2

Image depth is length of actual data type used for storing image (integer, char, float). In your case it seems to be char or unsigned char as depth is 8 bits.

Number of channels is a number of numbers, that describe a color of the particular pixel (e.g. RGB - 3 channels).

Alex
  • 9,891
  • 11
  • 53
  • 87