Loop Help
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi I am working on following data hiding algorithm in images using Matlab
Example: Suppose the cipher text to be sent is: 11001011 01111010 10101010 10011001 01010101. This data is five bytes. So n=5 and p=2. Suppose the different bytes of the digital image are A,B,C,D,E etc. From table-3 we can see that in byte A of the carrier file we embeded the data bits 11 in 6th and 8th bit locations, and next value of p becomes 0. We embed the next data bits 00 into byte B in 6th and 7th bit locations, next value of p becomes 1. Now we embed the next two bits 10 in C in 7th and 8th bit locations and so on.
Carrier FileByte Operation location IndexVariable,P
Byte A Embed (11) 6th and 8th 2
Byte B Embed (00) 6th and 7th 0
Byte C Embed (10) 7th and 8th 1
Byte D Embed (11) 6th and 8th 2
Byte E Embed (01) 6th and 7th 0
Byte F Embed (11) 7th and 8th 1
Byte G Embed (10) 6th and 8th 2
Byte H Embed (10) 6th and 7th 0
Byte I Embed (10) 7th and 8th 1
Byte J Embed (10) 6th and 8th 2
Byte K Embed (10) 6th and 7th 0
Byte L Embed (10) 7th and 8th 1
so on………
I have used following logic-
I have converted image into row format and storing the ciphertext length in 7th&8th bits of first four pixles
using below logic in attached file for this
pv=v(1,1);
pb=dec2bin(pv,8);
pb(7)=b(1);
pb(8)=b(2);
pv=bin2dec(pb);
v(1,1)=pv;
pv=v(1,2);
pb=dec2bin(pv,8);
pb(7)=b(3);
pb(8)=b(4);
pv=bin2dec(pb);
v(1,2)=pv;
pv=v(1,3);
pb=dec2bin(pv,8);
pb(7)=b(5);
pb(8)=b(6);
pv=bin2dec(pb);
v(1,3)=pv;
pv=v(1,4);
pb=dec2bin(pv,8);
pb(7)=b(7);
pb(8)=b(8);
pv=bin2dec(pb);
v(1,4)=pv;
Now I want to store bits of my ciphertext following way
Say ciphertext is 11001011 01111010 10101010 10011001 01010101
This data is five bytes. So n=5 therefore p=2 ((Mod(n,3))
Carrier FileByte Operation location IndexVariable,P
(1,5) Embed (11) 6th and 8th 2
(1,6) Embed (00) 6th and 7th 0
(1,7) Embed (10) 7th and 8th 1
(1,8) Embed (11) 6th and 8th 2
(1,9) Embed (01) 6th and 7th 0
(1,10) Embed (11) 7th and 8th 1
(1,11) Embed (10) 6th and 8th 2
(1,12) Embed (10) 6th and 7th 0
(1,13) Embed (10) 7th and 8th 1
(1,14) Embed (10) 6th and 8th 2
(1,15) Embed (10) 6th and 7th 0
(1,16) Embed (10) 7th and 8th 1
--so on
But i am not getting how to implement above logic..
I am calculating index variable and based on its value taking locations as fixed..in this case p=2 so embedding data in each 6th and 8th bit locations of next pixels which is not as per above table.. I am struggling in framing above logic in Matlab where bit locations and index variable are changing.
my code as below. pls provide me direction
Thanks in Advance
my code--
global l ciphertxt;
[f p]=uigetfile('*.*','Open Cover Image');
fp=[p f];
im=imread(fp);
[r c n]=size(im);
if n==3
im=rgb2gray(im);
end
figure;
imshow(im)
title('Input Image')
v=reshape(im,1,r*c);
b=dec2bin(l,8);
pv=v(1,1);
pb=dec2bin(pv,8);
pb(7)=b(1);
pb(8)=b(2);
pv=bin2dec(pb);
v(1,1)=pv;
pv=v(1,2);
pb=dec2bin(pv,8);
pb(7)=b(3);
pb(8)=b(4);
pv=bin2dec(pb);
v(1,2)=pv;
pv=v(1,3);
pb=dec2bin(pv,8);
pb(7)=b(5);
pb(8)=b(6);
pv=bin2dec(pb);
v(1,3)=pv;
pv=v(1,4);
pb=dec2bin(pv,8);
pb(7)=b(7);
pb(8)=b(8);
pv=bin2dec(pb);
v(1,4)=pv;
l=length(ciphertxt);
for i=1:l
t=ciphertxt(i);
n=abs(t);
b1=dec2bin(n,8);
p=mod(l,3);
%%%%%%%%%here i want my index variable and bit locations dynamic to store data after 4th pixel as below
%%Carrier FileByte Operation location IndexVariable,P
%%%(1,5) Embed (11) 6th and 8th 2
%%(1,6) Embed (00) 6th and 7th 0
%%(1,7) Embed (10) 7th and 8th 1
%%(1,8) Embed (11) 6th and 8th 2
%%%%%%%%%
if p==0
pv=v(1,(i-1)*4+5);
b2=dec2bin(pv,8);
b2(6)=b1(1);
b2(7)=b1(2);
nn=bin2dec(b2);
v(1,(i-1)*4+5)=nn;
pv=v(1,(i-1)*4+6);
b2=dec2bin(pv,8);
b2(6)=b1(3);
b2(7)=b1(4);
nn=bin2dec(b2);
v(1,(i-1)*4+6)=nn;
pv=v(1,(i-1)*4+7);
b2=dec2bin(pv,8);
b2(6)=b1(5);
b2(7)=b1(6);
nn=bin2dec(b2);
v(1,(i-1)*4+7)=nn;
pv=v(1,(i-1)*4+8);
b2=dec2bin(pv,8);
b2(6)=b1(7);
b2(7)=b1(8);
nn=bin2dec(b2);
v(1,(i-1)*4+8)=nn;
end
if p==1
pv=v(1,(i-1)*4+5);
b2=dec2bin(pv,8);
b2(7)=b1(1);
b2(8)=b1(2);
nn=bin2dec(b2);
v(1,(i-1)*4+5)=nn;
pv=v(1,(i-1)*4+6);
b2=dec2bin(pv,8);
b2(7)=b1(3);
b2(8)=b1(4);
nn=bin2dec(b2);
v(1,(i-1)*4+6)=nn;
pv=v(1,(i-1)*4+7);
b2=dec2bin(pv,8);
b2(7)=b1(5);
b2(8)=b1(6);
nn=bin2dec(b2);
v(1,(i-1)*4+7)=nn;
pv=v(1,(i-1)*4+8);
b2=dec2bin(pv,8);
b2(7)=b1(7);
b2(8)=b1(8);
nn=bin2dec(b2);
v(1,(i-1)*4+8)=nn;
end
if p==2
pv=v(1,(i-1)*4+5);
b2=dec2bin(pv,8);
b2(6)=b1(1);
b2(8)=b1(2);
nn=bin2dec(b2);
v(1,(i-1)*4+5)=nn;
pv=v(1,(i-1)*4+6);
b2=dec2bin(pv,8);
b2(6)=b1(3);
b2(8)=b1(4);
nn=bin2dec(b2);
v(1,(i-1)*4+6)=nn;
pv=v(1,(i-1)*4+7);
b2=dec2bin(pv,8);
b2(6)=b1(5);
b2(8)=b1(6);
nn=bin2dec(b2);
v(1,(i-1)*4+7)=nn;
pv=v(1,(i-1)*4+8);
b2=dec2bin(pv,8);
b2(6)=b1(7);
b2(8)=b1(8);
nn=bin2dec(b2);
v(1,(i-1)*4+8)=nn;
end
end
steg=uint8(reshape(v,r,c));
figure;
imshow(steg)
title('Stego Image')
[f p]=uiputfile('*.bmp','Save Stego Image');
fp=[p f];
imwrite(steg,fp);
3 comentarios
Jan
el 12 de Mzo. de 2012
I do not understand the question. What is "above logic" in "But i am not getting how to implement above logic"?
Respuestas (0)
Ver también
Categorías
Más información sobre Embedded Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!