Clear Filters
Clear Filters

i'm working with image ,i cant load 512*512 image

1 view (last 30 days)
all time i face a error
Attempted to access N(1,1,3); index out of bounds because size(N)=[256,256,1].my code is here:
function [mg_length,mes] = embed_file(image_file1,text_file1)
clc
M=imread(image_file1); [X,Y,V] = size(M);
disp(sprintf('%d %d %d',X,Y,V));
%N=rgb2gray(M);
N=M;
T=N;
str={};
z='';
count=0;
fid = fopen(text_file1);
tline = fgetl(fid);
while ischar(tline)
if(length(tline)==0)
z=[z,char(dec2bin(13,8))];
z=[z,char(dec2bin(10,8))];
else
str=[str,tline];
t= dbinary(str);
if(count~=0)
z=[z,char(dec2bin(13,8))];
z=[z,char(dec2bin(10,8))];
end
z=[z,t];
end
count=count+1;
tline = fgetl(fid);
str='';
end
mes='';
disp(z); %disp(N);
imageSize=X*Y;
key=length(z);
mg_length=key;
disp('message length');
disp(key);
if(imageSize>key)
mes='embed successful';
d=1;
for i=1:X
for j=1:Y
a=N(i,j,3);
b=z(1,d);
[T(i,j,3),p]=changeImage2(a,b,key);
%a=N(i,j,2);
%[T(i,j,2),p]=changeImage2(a,b,length_Z);
%a=N(i,j,3);
%[T(i,j,3),p]=changeImage2(a,b,length_Z);
if(d==key)
break;
end
if(p==1)
d=d+1;
end
end
if(d==key)
break;
end
end
how can i fix it ?

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Nov 2014
Farjana - the error message is occurring because of the line of code
a=N(i,j,3);
which is trying to access the third dimension of the matrix N when it only has two dimensions (your input image is grayscale, 256x256, and not colour, 256x256x3). Either change the line of code to
a=N(i,j);
or select a colour image.
  4 Comments
Image Analyst
Image Analyst on 24 Nov 2014
Farjana, the code was meant for color images. Since you have grayscale images, you commented out the color part but that's not all you need to do. You need to change the line of code that Geoff told you to. You probably also want to change T(i,j,3) to T(i,j).

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!