4
votes

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
To have 225x300x3 image you should have three channel color image where each channel is represented using a unit8. You can see the colors can be represented using one channel 8bit color range from this link. en.wikipedia.org/wiki/8-bit_colorSavrona
“So how can we have colored images of 4,8,10, etc., bits represented and created?” 4-bit images are stored using one byte (8 bits) per pixel. This can be reduced to half the number of bytes for storing to file, but it’s not worth the effort to do so in memory, as it makes everything much more difficult. Image processing libraries usually only deal with 8-bit, 16-bit, etc. images in memory. Same for 10-bit or 12-bit images, which are represented as 16-bit images.Cris Luengo
Do we in practice don't use these 4-bit, 10-bit, and 12-bit images and instead use 8-bit and 16-bit since when storing 4-bit and 8-bit both are represented by 8-bit?Manas Satti

1 Answers

6
votes

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)