# Indexed image in Matlab

#### Pooja Pandey ##### Indexed image in Matlab
« on: May 09, 2017, 12:37:47 PM »
I am trying to use an indexed image in matlab and for reading the same, used the command
[x, map]=imread('data2.tiff');
I am new to matlab, want to use the x or cdata in my script. Please let me know how to load the same.

#### Karthikeyan L ##### Re: Indexed image in Matlab
« Reply #1 on: May 10, 2017, 10:23:00 AM »
An indexed image is useful to represent the image which has limited number of colors in it so as to reduce the space consumption (of the image). As the name suggests, an indexed image is a matrix of indexes with each number pointing to the color in the colormap matrix.

Say you have an image with only three colors red, green and blue and no other color, its indexed image X (assuming it to be a 4x4 matrix image) could look something like this:
Code: [Select]
`X=[3,2,2,1;1,3,1,2;1,2,1,2];`And the corresponding colormap matrix will be:
Code: [Select]
`map=[1,0,0;0,1,0;0,0,1];`Here map will be 3x3 matrix with rows indicating number of colors (which is three in this example) and columns indicating R,G,B (the numbers will be varying between [0,1]).
For example, 3 in X simply points to 3rd row in map matrix and takes its corresponding color (which is blue).

Once you obtain index and colormap from an image, you can use them to get an RGB image by using ind2rgb
(http://in.mathworks.com/help/matlab/ref/ind2rgb.html) command. This command simply maps indexes to the colormap matrix and creates a 3D matrix where the third dimension contains the RGB colors. You can run following lines in matlab for better understanding:

Code: [Select]
`[X,map] = imread('corn.tif');RGB = ind2rgb(X,map);imagesc(RGB);`

The following users thanked this post: Pooja Pandey

#### Pooja Pandey ##### Re: Indexed image in Matlab
« Reply #2 on: May 11, 2017, 10:03:28 AM »
could you please send me an example where an indexed image is used

#### Karthikeyan L ##### Re: Indexed image in Matlab
« Reply #3 on: May 11, 2017, 11:48:36 AM »
The example that I have given towards the end is for the indexed image. 'corn.tif' is an indexed image.

#### Pooja Pandey ##### Re: Indexed image in Matlab
« Reply #4 on: May 11, 2017, 12:13:03 PM »
when I am trying to use the cdata in the code, programme couldn't read the values,it's reading number of rows and columns.