# how to hide a binary image within an rgb image?

1 view (last 30 days)
chaithra on 29 Jan 2014
i dont know matlab very well.i have written a code to hide binary image in an rgb image.but it does not work very well.the traces of the binary image can be seen in the rgb image after encrypting.how do i improve it?
%encryption
p1=im2bw(p,.2);
[r c]=size(s);
[r1 c1]=size(q1);
figure(1),imshow(q1),title('original');
q1=imresize(q1,[r,c]);
qr=q1(:,:,1);
qg=q1(:,:,2);
qb=q1(:,:,3);
j=1;
length=r*c;
for i=1:length
if p1(i)==0
qr(j)=bitand(qr(j),0);
j=j+1;
else
qr(j)=bitor(qr(j),1);
j=j+1;
end
end
im=cat(3,qr,qg,qb);
figure(2),imshow(s);
%im=imresize(im,[r1 c1]);
figure(3),imshow(im),title('final');
==================================
%decryption
ir=im(:,:,1);
ig=im(:,:,2);
ib=im(:,:,3);
sz=size(ir);
l=sz(1)*sz(2);
d=zeros(r,c);
j=1;
for i=1:l
d(j)=bitand(ir(i),1);
j=j+1;
end
imshow(d);

Shivaputra Narke on 29 Jan 2014
You can use watermarking using DCT

Shivaputra Narke on 29 Jan 2014
Edited: Walter Roberson on 11 Jan 2016
I have written a simple code...
clear all;
%%%both images must be of same size
%%%use imresize if its not
onesPosn=find(signature==1);
zerosPosn=find(signature==0);
host=imresize(host,[size(signature)]);
host_R =host(:,:,1);
host_G =host(:,:,2);
host_B =host(:,:,3);
host_R2=host_R;
host_R2(onesPosn)=bitor(host_R(onesPosn),1);
host_R2(zerosPosn)=bitand(host_R(zerosPosn),254);
encrypted=cat(3,host_R2,host_G,host_B);
figure;
subplot(2,2,1);imshow(host);title('original image')
subplot(2,2,2);imshow(signature);title('Binary image')
subplot(2,2,3);imshow(host_R);title('host RED plane')
subplot(2,2,4);imshow(encrypted);title('encrypted')
%-------------------------------------------------
%Decryption
dec_host_R=encrypted(:,:,1);
dec_signature=bitand(dec_host_R,1);
figure;
imshow(dec_signature,[]);title('Decrypted signature');
Ishara Kariyawasam on 19 Jan 2021
How to save this decrypt image?

### Categories

Find more on Watermarking in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!