why Index exceeds the number of array elements (906309).

Index exceeds the number of array elements (906309).
Error in code (line 17)
data2(i)=Data2(i);
clear
clc
Path1='F:\2\ChangeDetectionDataset-master-7b2095f8882d3f5a4e20271496eb0529e0c5150e\bayArea\rgb\bayArea2013rgb.png';
Path2='F:\2\ChangeDetectionDataset-master-7b2095f8882d3f5a4e20271496eb0529e0c5150e\bayArea\rgb\bayArea2015rgb.png';
Data1=imread(Path1);
figure(1);imshow(Data1);
Data2=imread(Path2);
figure(2);imshow(Data2);
[row,col]=size(Data1);
data1=zeros(row,col);
data2=zeros(row,col);
data=zeros(row,col);
DATA=zeros(row,col);
for i=1:1:row*col
data1(i)=Data1(i);
data2(i)=Data2(i);
data(i)=data1(i)-data2(i);
end
for i=1:row*col
if (data(i))<60
DATA(i)=0;
% elseif (abs(data(i))>=20)&&(abs(data(i))<40)
% DATA(i)=2;
% elseif (abs(data(i))>=40)&&(abs(data(i))<60)
% DATA(i)=3;
% elseif (abs(data(i))>=60)&&(abs(data(i))<80)
% DATA(i)=4;
% elseif (abs(data(i))>=80)&&(abs(data(i))<100)
% DATA(i)=5;
% elseif (abs(data(i))>=100)&&(abs(data(i))<120)
% DATA(i)=6;
% elseif (abs(data(i))>=120)&&(abs(data(i))<140)
% DATA(i)=7;
elseif abs(data(i))>=60
DATA(i)=1;
end
end
figure(3);
imagesc(DATA);
saveas(gcf,'检测效果.jpg');
b1=reshape(data1,row*col,1);
b2=reshape(data2,row*col,1);

1 Comment

We have no reason to believe that the images are the same size.
We suspect that the images are rgb not grayscale

Sign in to comment.

Answers (0)

Asked:

on 19 Sep 2020

Commented:

on 19 Sep 2020

Community Treasure Hunt

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

Start Hunting!