%om sairam
clc;
close all;
I = imread('C:\MATLAB701\work\iris.bmp');
subplot(2,4,1),imshow(I,[]);title('Original Image');
I_g=rgb2gray(I);
key =[1; 2; 3; 4; 5; 6; 7; 8];
subplot(2,4,3),imshow(key,[]);title('Key image');
I=double(I_g); % convert to type double as '+' and '-' are not possible for uint8
for i=1:8
m=key(i,1); n=m;
I_g(m,n)=bitset(I_g(m,n),1,0); %set the LSB of all pixels to zero
end;
I_g=uint8(I_g); %convert back to uint8 as the image can be displayed as uint8 format only
subplot(2,4,2),imshow(I_g,[]);title('LSB set to zero Image');
I_d = double(I_g);
[U,S,V] = svd(I_d);
[ms,ns]=size(S);
clc;
close all;
I = imread('C:\MATLAB701\work\_lena_std_bw.bmp');
subplot(2,4,1),imshow(I,[]);title('Original Image');
key =[12; 18; 16; 13; 14; 15; 10; 21; 34; 43; 54; 65; 70; 71; 72; 73; 74; 75; 80; 81; 82; 83; 84; 85; 100; 101; 102; 103; 104; 105; 120; 121; 132; 133;144;155 ];
subplot(2,4,3),imshow(key,[]);title('Key image');
I=double(I); % convert to type double as '+' and '-' are not possible for uint8
for i=1:36
m=key(i,1); n=m;
I(m,n)=bitset(I(m,n),1,0); %set the LSB of all pixels to zero
end;
I=uint8(I); %convert back to uint8 as the image can be displayed as uint8 format only
subplot(2,4,2),imshow(I,[]);title('LSB set to zero Image');
I_d = double(I);
[U,S,V] = svd(I_d);
[ms,ns]=size(S);
for i=1:36
m=key(i,1); n=m;
S(m,n) = round(10*S(m,n));
B(i,1)=mod(S(m,n),2);
end;
subplot(2,4,4),imshow(B);title('Binary image');
for i=1:36
m=key(i,1); n=m;
I_d(m,n)=bitset(I_d(m,n),1,B(i,1));
end;
I_d=uint8(I_d);
subplot(2,4,5),imshow(I_d,[]);title('Watermark embedded image');
Watermarked_image=double(I_d);
for i=1:36
m=key(i,1); n=m;
E(i,1)=bitget(Watermarked_image(m,n),1);
end;
disp(E);
subplot(2,4,6),imshow(E,[]);title('Extracted image');
for i=1:36
m=key(i,1); n=m;
Watermarked_image(m,n)=bitset(Watermarked_image(m,n),1,0);
end;
[U1,S1,V1] = svd(Watermarked_image);
for i=1:36
m=key(i,1); n=m;
S1(m,n)=round(10*S1(m,n));
C(i,1) = mod(S1(m,n),2);
end;
disp(C);
subplot(2,4,8),imshow(C,[]);title('watermark extracted');