How to solve Index exceeds matrix dimensions?

1 次查看(过去 30 天)
Hello, can anybody please give me advices how to solve this: I have 3 images and I would like to noise this images with 2 kind of noise and save to cell array. When I have cell array 3x3 it works well. It looks like this:
clc, clear all, close all
a = imread ('mri1.jpg')
b = imread ('mri2.png')
im3 = imread ('mri3.jpg')
im1 = rgb2gray (a)
im2 = rgb2gray (b)
pole = {im1 false false ;
im2 false false ;
im3 false false }
[n,m]=size(pole);
for i = 1 : m
for j = 1 : n
if j == 2
pole{i,2} = imnoise (pole{i,1},'salt & pepper',0.02);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 3
pole{i,3} = imnoise (pole{i,1},'salt & pepper',0.1);
end
end
end
But when I decided to give to cell array next column (where I would like to save other kind of noise) it collaps with error: Index exceeds matrix dimensions. It looks like:
clc, clear all, close all
a = imread ('mri1.jpg')
b = imread ('mri2.png')
im3 = imread ('mri3.jpg')
im1 = rgb2gray (a)
im2 = rgb2gray (b)
pole = {im1 false false false;
im2 false false false;
im3 false false false}
[n,m]=size(pole);
for i = 1 : m
for j = 1 : n
if j == 2
pole{i,2} = imnoise (pole{i,1},'salt & pepper',0.02);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 3
pole{i,3} = imnoise (pole{i,1},'salt & pepper',0.1);
end
end
end
for i = 1 : m
for j = 1 : n
if j == 4
pole{i,4} = imnoise (pole{i,1},'gaussian',0.1,0.01);
end
end
end
How should I solve this?

回答(1 个)

Jose Marques
Jose Marques 2017-11-13
Have you verify the size of the images? They must be the same.
  1 个评论
Martina  Polachová
Martina Polachová 2017-11-13
The size of the images is not the same. I thought the cell array could contain pictures of different sizes.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by