Why Index out of range?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone, I need assistance. I got an error "index exceeds matrix dimension"
with accessing the intensity of R, G and B components of an image. My code is as shown below:
rgb=imread('car3.jpg'); %# Load an RGB image
rgb=num2cell(rgb);
rPlane = zeros(size(rgb,1),size(rgb,2));
gPlane = zeros(size(rgb,1),size(rgb,2));
bPlane = zeros(size(rgb,1),size(rgb,2));
rPlane=[size(rgb,1),size(rgb,2)];
gPlane=[size(rgb,1),size(rgb,2)];
bPlane=[size(rgb,1),size(rgb,2)];
for i = 1:size(rgb,1) %rows
for k=1:size(rgb,2) %columns
rPlane=rgb{i,k}(:,:,1);% j=1(:,:,k);
gPlane=rgb{i,k}(:,:,2);
bPlane=rgb{i,k}(:,:,3);%j=3
end
end
The error occurs at "gPlane=rgb{i,k}(:,:,2);" inside the nested for loop. The car3.jpg picture has the following dimension: rgb(302,435,:)
0 comentarios
Respuestas (1)
Walter Roberson
el 21 de Abr. de 2016
The result of num2cell() is going to be a cell array which each entry is a single scalar value. You are trying to access the third dimension of that scalar.
3 comentarios
Walter Roberson
el 21 de Abr. de 2016
rgb=imread('car3.jpg'); %# Load an RGB image
rPlane = rgb(:,:,1);
gPlane = rgb(:,:,2);
bPlane = rgb(:,:,3);
No loop needed.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!