Index exceeds the number of array elements (2). Error in Hindawi_Extract (line 20) msg=strcat​(msg,num2s​tr(m1(loop​)));

1 view (last 30 days)
I=imread('C:\Users\manav\Desktop\MinoR Project\Code\Digital-Image_Steganography-Using-8Directional-PVD-master\teapot.png');
var123=[];
final_msg=[];
i1=1;
checker='000000000000000000000000000000';
msg='';
while(i1<=510)
for j1=1:3:510
pixel_count=0;
for i=i1:i1+2
for j=j1:j1+2
pixel_count=pixel_count+1;
if(pixel_count==5)
A1=i;
A2=j;
m1=dec2bin(I(i,j),2);
for loop=3:-1:1
msg=strcat(msg,num2str(m1(loop)));
var123=strfind(msg,checker);
if(length(var123)>=1)
break
end
end
if(length(var123)>=1)
break
end
end
end
if(length(var123)>=1)
break
end
end
inner_loop=0;
for x1=i1:i1+2
for x2=j1:j1+2
inner_loop=inner_loop+1;
if(inner_loop~=5)
if(I(x1,x2)>I(A1,A2))
di=I(x1,x2)-I(A1,A2);
elseif(I(x1,x2)==I(A1,A2))
di=0;
else
di=I(A1,A2)-I(x1,x2);
end
if(di<8)
L=0;
ti=3;
elseif(di>7 && di<16)
L=8;
ti=3;
elseif(di>15 && di<32)
L=16;
ti=3;
elseif(di>31 && di<64)
L=32;
ti=3;
elseif(di>63 && di<128)
L=64;
ti=4;
else
L=128;
ti=4;
end
S=di-L;
binary_form=fliplr(dec2bin(S,ti));
for k=1:ti
msg=strcat(msg,num2str(binary_form(k)));
var123=strfind(msg,checker);
if(length(var123)>=1)
break
end
end
if(length(var123)>=1)
break
end
end
end
if(length(var123)>=1)
break
end
end
if(length(var123)>=1)
break
end
end
if(length(var123)>=1)
break
end
i1=i1+3;
end
lkj=var123(1);
lkj=lkj+6;
msg;
msg=msg(1:lkj);
msg;
final_msg=[];
ccc=0;
len_msg=floor(length(msg)/8);
for outer_loop=1:len_msg
ccc=ccc+1;
final_msg(outer_loop)=bin2dec(fliplr(msg(ccc:ccc+7)));
ccc=ccc+7;
end
final_msg=char(final_msg);
DISP("extract");

Answers (1)

Cris LaPierre
Cris LaPierre on 10 Dec 2020
Edited: Cris LaPierre on 10 Dec 2020
Let's break down the error message.
"Index exceeds the number of array elements (2). Error in Hindawi_Extract (line 20) msg=strcat(msg,num2str(m1(loop)));"
The error is in line 20, specifically
msg=strcat(msg,num2str(m1(loop)));
It is an indexing error, so we only have to inspect variables that are indexed.
m1(loop)
The index, which is loop, exceeds the number of array elements. Your array is m1, and it only has 2 elements (this is indicated by the (2) in the error message).
This means that either m1 is not the size you think it is, or loop contains a value larger than expected. Those are great places to start looking into your code to determine why it is not doing what you expect.

Tags

Community Treasure Hunt

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

Start Hunting!