How to solve Index exceeds matrix dimensions?

1 Ansicht (letzte 30 Tage)
Martina  Polachová
Martina Polachová am 13 Nov. 2017
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?

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by