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

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 ?

 Réponse acceptée

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 commentaires

but i can not fix the problem.. would you plz suggest me that how can i load image in all sizes in my code ?
Why is the reason that you are using this line of code
a=N(i,j,3);
Why not use
a=N(i,j,1);
instead?
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).
ok.. got a solution .. thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Display Image dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by