Image Steganography using Lsb ?

10 views (last 30 days)
Abduellah Elbakoush
Abduellah Elbakoush on 14 Jan 2022
Answered: Image Analyst on 17 Jan 2022
I am working In image steganography using Lsb , I am trying to do RGB Pixel Indicator ,I select red channel to use as Indicator
If Red channel 11 there is embeded data in both green and blue channels
If Red channel 01 there is embeded data in just blue channels
If Red channel 10 there is embeded data in just green channels
If Red channel 00 there is no data to embeded in both green and blue channels
I tried to implement this code, but I found an error when I extracted the text from the image I didn't understand it
What is wrong with this code? Can someone help me ?
So the embeding code is
function stego_img = HIDE(cover_img,txt_file)
stego_img=cover_img;
stego_img=double(stego_img);
f_id=fopen('msg-4000ch.txt','r');
[msg,len_total]=fread(f_id,'ubit2');
[m,n]=size(stego_img);
if len_total>m*n/3
error('overflow');
end
lengthtext=len_total/4000;
binary=dec2bin(lengthtext,8);
binarylen_total=[repmat('0',rem(length(binary),2)),binary]
matrixlen_total=reshape(binarylen_total,1,[])'-'0';
[xlen,ylen]=size(matrixlen_total);
k=1;
h=msg';
for f1=1
for f2=1:8
stego_img(f1,f2)=stego_img(f1,f2)-mod(stego_img(f1,f2),2)+matrixlen_total(k,1);
if k==xlen
break;
end
k=k+1;
end
if k==xlen
break;
end
end
p=1;
for f1=2:m
for f2=1:3:n
r=rem(stego_img(f1,f2),4);
if (r==3)
f2=f2+1;
stego_img(f1,f2)=stego_img(f1,f2)-mod(stego_img(f1,f2),4)+msg(p,1);
f2=f2+1;
stego_img(f1,f2)=stego_img(f1,f2)-mod(stego_img(f1,f2),4)+msg(p,1);
f2=f2-2;
elseif (r==1)
f2=f2+2;
stego_img(f1,f2)=stego_img(f1,f2)-mod(stego_img(f1,f2),4)+msg(p,1);
f2=f2-2;
elseif (r==2)
f2=f2+1;
stego_img(f1,f2)=stego_img(f1,f2)-mod(stego_img(f1,f2),4)+msg(p,1);
f2=f2-1;
else (r==0)
stego_img(f1,f2)=stego_img(f1,f2) ;
end
if p==len_total
break;
end
p=p+1;
end
if p==len_total
break;
end
end
stego_img=uint8(stego_img);
end
and the Retrive Code is
function LSB_EXTRACT(img,path,name)
img=double(img);
[m,n]=size(img);
path=strcat(path,name);
msg=fopen(path,'w+');
len_total=0;
for f1=1
for f2=1:8
img(1,f2)=rem(img(f1,f2),2);
len_total=len_total+( img(f1,f2)*4000*4);
end
end
p=1;
for f1=2:m
for f2=1:3:n
r=rem(img(f1,f2),4);
if (r==3)
f2=f2+1;
bit=bitand(img(f1,f2),3);
if (bit==0);
fwrite(msg,00,'ubit2');
elseif (bit==1);
fwrite(msg,01,'ubit2');
elseif (bit==2);
fwrite(msg,10,'ubit2')
else (bit==3);
fwrite(msg,11,'ubit2')
end
f2=f2+1;
bit=bitand(img(f1,f2),3);
if (bit==0);
fwrite(msg,00,'ubit2');
elseif (bit==1);
fwrite(msg,01,'ubit2');
elseif (bit==2);
fwrite(msg,10,'ubit2')
else (bit==3);
fwrite(msg,11,'ubit2')
end
f2=f2-2;
elseif (r==1)
f2=f2+2;
bit=bitand(img(f1,f2),3);
if (bit==0);
fwrite(msg,00,'ubit2');
elseif (bit==1);
fwrite(msg,01,'ubit2');
elseif (bit==2);
fwrite(msg,10,'ubit2')
else (bit==3);
fwrite(msg,11,'ubit2')
end
f2=f2-2;
elseif (r==2)
f2=f2+1;
bit=bitand(img(f1,f2),3);
if (bit==0);
fwrite(msg,00,'ubit2');
elseif (bit==1);
fwrite(msg,01,'ubit2');
elseif (bit==2);
fwrite(msg,10,'ubit2')
else (bit==3);
fwrite(msg,11,'ubit2')
end
f2=f2-1;
else (r==0)
img(f1,f2)=img(f1,f2) ;
end
if p==len_total
break;
end
p=p+1;
end
if p==len_total
break;
end
end
fclose(msg);
end

Answers (1)

Image Analyst
Image Analyst on 17 Jan 2022
See my LSB watermarking demo. Adapt as needed.

Community Treasure Hunt

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

Start Hunting!