필터 지우기
필터 지우기

Index exceeds matrix dimensions

조회 수: 1 (최근 30일)
SNEHA P S
SNEHA P S 2017년 7월 17일
댓글: Guillaume 2017년 7월 17일
Index exceeds matrix dimensions.
Error in test (line 19) newgreen = c(:,:,2);
I got an error like this while running the below code;
a = imread('lena.tif');
%imread(a);
%imgsize = getImgSize('image.jpg')
imshow(a)
img = imfinfo('lena.tif')
%I = rgb2gray(a);
%figure
%imshow(I)
red = a(:,:,1);
imshow(red)
green = a(:,:,2);
imshow(green)
blue = a(:,:,3);
imshow(blue)
c = horzcat(red,green,blue);
imshow(c)
newred = c(:,:,1);
imshow(red)
newgreen = c(:,:,2);
%imshow(green)
%newblue = c(:,:,3);
%imshow(blue)
how could i solve this ?
  댓글 수: 2
Ahmad Moniri
Ahmad Moniri 2017년 7월 17일
Are you sure the image is RGB and not grayscale? What does size(a) return for you?
Guillaume
Guillaume 2017년 7월 17일
If the error occurs at the indexing of c, then the image is definitively RGB. Otherwise, the error would occur at
red = a(:, :, 1);
Certainly, adding
assert(size(a, 3) == 3, 'Image is not RGB');
after the imread call would make the program more robust.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2017년 7월 17일
편집: Guillaume 2017년 7월 17일
how could i solve this ?
c = cat(3, red, green, blue);
You were contatenating your arrays horizontally, resulting in a array of size height x 3*width instead of an array height x width x 3.
Note that I don't see the purpose of your code. It creates c exactly the same as a, and newred, newgreen and newblue exactly the same as red, green, blue.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by