I have written the code below which takes the Haar transform of an image and embeds a secret message, bit by bit on in the least significant bits of the coefficients. To use the bitset function I convert the double coefficients to uint64 and I change them back after the embedding.
function DwtSteg(address,message)
coverImage=imread(address);
ascii=uint8(message);
[LL LH HL HH]=dwt2(coverImage,'haar');
LH=round(LH);
HL=round(HL);
subplot(1,2,1)
imshow(LH)
[r c]=size(LL);
wc=1;
bc=1;
done=false;
for i=1:r
if(done)
break
end
for j=1:c
if(bc==8)
bc=1;
wc=wc+1;
end
if(wc==length(message))
done=true;
break;
end
xb = typecast(LH(i,j), 'uint64' );
xb=bitset(xb,1,bitget(ascii(wc),bc));
xb%***
LH(i,j)=typecast(xb, 'double');
bc=bc+1;
end
end
subplot(1,2,2)
imshow(LH)
stegoImage=idwt2(LL ,HL,LH, HH,'haar');
figure(2)
imshow(uint8(stegoImage));
imwrite(uint8(stegoImage),'stegoImage.tiff');
end
But when I run below code to extract my message from Image.The coefficients aren't same as the converted ones.(consider '***' on both function) :
function [ str ] = DwtDesteg( address)
str='';
image=imread(address);
[LL LH HL HH]=dwt2(image,'haar');
[r c]=size(LL);
LH=round(LH);
bc=1;
ch=0;
for i=1:r
for j=1:c
if(bc==8)
bc=1;
str=strcat(str,ch);
char(ch)
end
xb = typecast(LH(i,j), 'uint64');
xb%***
ch=bitset(ch,bc,bitget(xb,1));
bitget(xb,1)
bc=bc+1;
end
end
end