Asked by Abed
on 10 Nov 2013

when I use imread(X, map)... function for a picture and write whos, matrix X and matrix map suppose to be a [n m] and [n 3] respectively. However, when I do it, matrix X and map will be shown as [n m 3] and [0 0] respectively! what should I do to convert it into the way it suppose to be????

*No products are associated with this question.*

Answer by Walter Roberson
on 10 Nov 2013

Accepted Answer

The map is returned as empty if it is a truecolor image. If you want to convert it to an indexed image for some reason, use rgb2ind()

Abed
on 10 Nov 2013

Thank u..it works now. However, I am wondering why the truecolor original image is different from the image obtained by : image(X); colormap(map) when you convert it to indexed one???

Walter Roberson
on 10 Nov 2013

rgb2ind() does an approximation.

[X,map] = rgb2ind(RGB,n) converts the RGB image to an indexed image X using minimum variance quantization and dithering. map contains at most n colors. n must be less than or equal to 65,536.

So you tell it how many colors you want your map to be, and it figures out the set of colors that gives you the least total error between original colors and the colors in the output map.

Abed
on 10 Nov 2013

Thanks a lot...actually I reviewed the wavelet 2D in Matlab wavelet toolbox book. There is an example that it converts an indexed image to gray scale before starts decomposing. I copied it exactly for my image but in one line an error pops up that I dont know why?? my program is this:

GOH = imread('hslc_L9.jpg'); [m,p,r] = size(GOH); [X2,map] = rgb2ind(GOH, m); R = map(X2,1); R = reshape(R,size(X2)); G = map(X2,2); G = reshape(G,size(X2)); B = map(X2,3); B = reshape(B,size(X2));

in line 4 this error pops up: **Subscript indices must either be real positive integers or logicals.**

Log in to comment.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments

Log in to comment.