8-bit color image matrix representation

Viewed 278

I have just started learning image processing by myself, and I am using MATLAB. I have been getting myself familiarized with basic image operations. When I read the below image(res: 225x300), which is supposed to be an 8-bit color image, I expected the resultant matrix to have 3 dimensions with one each for RGB. A simple web search about 8-bit color image led me to Wikipedia with the following information:

The simplest form of quantization frequently called 8-bit truecolor is to simply assign 3 bits to red, 3 to green and 2 to blue (the human eye is less sensitive to blue light) to create a 3-3-2.

Therefore, I expected the image matrix to have 225x300x3 dimensions with the above distribution of bits b/w RGB. But after I checked the dimensions of the matrix of the image, I found it to be 225x300 unit8, which is what one expects from an 8-bit grayscale image. But the image is a color image, as seen by any image viewer. So what is that I lack in knowledge or doing wrong? Is the problem with how I read the image?

Also, it occurred to me that uint8 is the smallest unsigned integer class. So how can we have colored images of 4,8,10, etc., bits represented and created?

My code:

>> I_8bit = imread('input_images\8_bit.png');
>> size(I_8bit)
ans =
   225   300
>> class(I_8bit)
ans =
    'uint8'
>> I_24bit = imread('input_images\24_bit.png');
>> size(I_24bit)
ans =
   225   300     3
>> class(I_24bit)
ans =
    'uint8'

8-bit color image

(source: https://en.wikipedia.org/wiki/Color_depth#/media/File:8_bit.png)

1 Answers

Matlab supports several types of images, including

  • RGB images, which allow arbitrary colors, stored in terms of R,G,B components. The image is defined by a 3D m×n×3 array
  • Indexed images, in which each pixel is defined by an index to a colormap. The image is defined by a 2D m×n array and a c×3 colormap, where c si the number of colors.

It looks like the image you are loading is indexed. So you need the two-output version of imread to get the 2D array and the colormap:

[I_8bit, cmap] = imread('input_images\8_bit.png');

To display the image you need to specify the 2D array and the colormap:

imshow(I_8bit, cmap)

You can see the effect of changing the colormap, for example

cmap_wrong = copper(size(cmap, 1)); % different colormap with the same size
imshow(I_8bit, cmap_wrong)

To convert to an RGB image, use ind2rgb:

I_8bit_RGB = ind2rgb(I_8bit, cmap);

which then you can display as

imshow(I_8bit_RGB)
Related