Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

i am executing the code below in which i am getting the error"Index exceeds matrix dimensions. Error in principale_peppers (line 7) g=X(:,:,2)/255;" how to solve it. can anyone solve it for me

1 Ansicht (letzte 30 Tage)
X=imread('d:\images\peppers.bmp'); X=double(X);
[l1,l2,l3]=size(X);
r=X(:,:,1)/255;
g=X(:,:,2)/255;
b=X(:,:,3)/255;
%figure(1),imshow(r)figure(2),imshow(g)figure(3),imshow(b)
r2=zeros(l1,l2,3); r2(:,:,1)=r;
g2=zeros(l1,l2,3); g2(:,:,2)=g;
b2=zeros(l1,l2,3); b2(:,:,3)=b; m1=240;

Antworten (1)

Stephen23
Stephen23 am 3 Mär. 2015
Bearbeitet: Stephen23 am 3 Mär. 2015
The imread documentation states: The return value A is an array containing the image data. If the file contains a grayscale image, A is an M-by-N array. If the file contains a truecolor image, A is an M-by-N-by-3 array.
The image is likely not in color, but saved as grayscale or indexed. If an image is grayscale or indexed, then it has only size M*N, and does not have a page for each of R, G and B. Only truecolor images have size M*N*3. You can read more in the documentation:
To demonstrate this I created a small image (attached) and read it into MATLAB, where it is clear that it only has one page:
>> imread('test.bmp')
ans =
1 1 1 1 1 1
1 1 0 1 1 1
1 0 0 1 1 1
1 1 0 0 0 1
1 1 0 0 0 1
1 1 0 1 0 1
1 1 0 1 0 1
1 0 0 0 0 0
1 1 1 1 1 1
Depending on what kind of image it is you might need to get the map value from imread too.

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by