Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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 (최근 30일)
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;

답변 (1개)

Stephen23
Stephen23 2015년 3월 3일
편집: Stephen23 2015년 3월 3일
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.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by