LAMPIRAN 1
1. Penyisipan Watermarking
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
try
if (nargout)
else
end
catch
disp(lasterr);
end
end
proyek=guidata(gcbo);
[namafile,direktori]=uigetfile({'*.bmp';'*.png';'*.tif';'*.jpg'},'Buka Gambar');
Asli=imread(namafile);
set(proyek.figure1,'currentAxes',proyek.GbrAsli);
set(imshow(Asli));
set(proyek.GbrAsli,'Userdata',Asli);
imwrite(Asli,'Asli.bmp','bmp');
% --------------------------------------------------------------------
proyek=guidata(gcbo);
watermark=imread(namafile);
set(proyek.figure1,'currentAxes',proyek.GbrWatermark);
set(imshow(watermark));
set(proyek.GbrWatermark,'Userdata',watermark);
imwrite(watermark,'watermark.bmp','bmp');
% --------------------------------------------------------------------
proyek=guidata(gcbo);
start_time=cputime;
file_name='Asli.bmp';
cover_object=double(imread(file_name));
Mc=size(cover_object,1); %Panjang
Nc=size(cover_object,2); %Lebar
file_name='watermark.bmp';
message=double(imread(file_name));
Mm=size(message,1); %Panjang
Nm=size(message,2); %Lebar
message_vector=round(reshape(message,Mm*Nm,1)./256);
file_name='_key.bmp';
key=double(imread(file_name))./256;
rand('state',key);
[cA1,cH1,cV1,cD1] = dwt2(cover_object,'haar');
set(proyek.figure1,'currentAxes',proyek.GbrCv);
set(imshow(uint8(cV1)));
set(proyek.GbrCv,'Userdata',cV1);
set(proyek.figure1,'currentAxes',proyek.GbrCh);
set(imshow(uint8(cH1)));
set(proyek.GbrCh,'Userdata',cH1);
set(proyek.figure1,'currentAxes',proyek.GbrCd);
set(proyek.GbrCd,'Userdata',cD1);
set(proyek.figure1,'currentAxes',proyek.GbrCa);
set(imshow(uint8(cA1)));
set(proyek.GbrCa,'Userdata',cA1);
for (kk=1:length(message_vector))
pn_sequence_h=round(2*(rand(Mc/2,Nc/2)-0.5));
pn_sequence_v=round(2*(rand(Mc/2,Nc/2)-0.5));
if (message(kk) == 0)
cH1=cH1+k*pn_sequence_h;
cV1=cV1+k*pn_sequence_v;
end
end
watermarked_image = idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]);
watermarked_image_uint8=uint8(watermarked_image);
imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');
elapsed_time=cputime-start_time,
psnr=psnr(cover_object,watermarked_image_uint8,Mc,Nc),
set(proyek.figure1,'CurrentAxes',proyek.GbrWatermarked);
2. Ekstraksi Watermarking
fig = openfig(mfilename,'reuse');
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
if (nargout)
else
end
catch
disp(lasterr);
end
end
% --------------------------------------------------------------------
proyek=guidata(gcbo);
[namafile,direktori]=uigetfile({'*.bmp';'*.png';'*.tif';'*.jpg'},'Buka Gambar');
Watermarked=imread(namafile);
set(proyek.figure1,'currentAxes',proyek.GbrWatermarked);
set(imshow(Watermarked));
set(proyek.GbrWatermarked,'Userdata',Watermarked);
imwrite(Watermarked,'watermarked.bmp','bmp');
% --------------------------------------------------------------------
proyek=guidata(gcbo);
start_time=cputime;
file_name='watermarked.bmp';
watermarked_image=double(imread(file_name));
Mw=size(watermarked_image,1); %Panjang
Nw=size(watermarked_image,2); %Lebar
file_name='watermark.bmp';
orig_watermark=double(imread(file_name));
Mo=size(orig_watermark,1); %Panjang
No=size(orig_watermark,2); %Lebar
file_name='_key.bmp';
key=double(imread(file_name))./256;
rand('state',key);
message_vector=ones(1,Mo*No);
[cA1,cH1,cV1,cD1] = dwt2(watermarked_image,'haar');
set(imshow(uint8(cV1)));
set(proyek.figure1,'currentAxes',proyek.GbrCh);
set(imshow(uint8(cH1)));
set(proyek.figure1,'currentAxes',proyek.GbrCd);
set(imshow(uint8(cD1)));
set(proyek.figure1,'currentAxes',proyek.GbrCa);
set(imshow(uint8(cA1)));
for (kk=1:length(message_vector))
pn_sequence_h=round(2*(rand(Mw/2,Nw/2)-0.5));
pn_sequence_v=round(2*(rand(Mw/2,Nw/2)-0.5));
correlation_h(kk)=corr2(cH1,pn_sequence_h);
correlation_v(kk)=corr2(cV1,pn_sequence_v);
correlation(kk)=(correlation_h(kk)+correlation_v(kk))/2;
end
for (kk=1:length(message_vector))
message_vector(kk)=0;
end
message=reshape(message_vector,Mo,No);
set(proyek.figure1,'currentAxes',proyek.GbrWatermark);
set(imshow(message));
elapsed_time=cputime-start_time,
LAMPIRAN 2
47 73 47 30 45 37 27 8
67 69 46 42 63 26 24 14
72 40 59 36 62 11 15 57
67 35 72 52 51 35 30 83
39 37 65 61 41 20 24 70
51 70 54 68 37 36 111 88
64 50 44 50 44 48 119 148
86 46 50 37 34 86 99 145
½ ½ 0 0 0 0 0 0
½ -½ 0 0 0 0 0 0
0 0 ½ ½ 0 0 0 0
0 0 ½ -½ 0 0 0 0
0 0 0 0 ½ ½ 0 0
0 0 0 0 ½ -½ 0 0
0 0 0 0 0 0 ½ ½
0 0 0 0 0 0 ½ -½
½ ½ 0 0 0 0 0 0 47 57
½ -½ 0 0 0 0 0 0 67 -10
0 0 ½ -½ 0 0 0 0 * 67 = 2.5
0 0 0 0 ½ ½ 0 0 39 45
0 0 0 0 ½ -½ 0 0 51 - 6
0 0 0 0 0 0 ½ ½ 64 75
0 0 0 0 0 0 ½ -½ 86 -11
Keterangan:
4. Setelah itu, lakukan hal yang sama dengan cara mengambil perbaris.
½ ½ 0 0 0 0 0 0 57 64
½ -½ 0 0 0 0 0 0 71 -7
0 0 ½ ½ 0 0 0 0 46.5 41.25
0 0 ½ -½ 0 0 0 0 * 36 = 5.25
0 0 0 0 ½ ½ 0 0 54 72.7
0 0 0 0 ½ -½ 0 0 31.5 11.25
0 0 0 0 0 0 ½ ½ 25.5 18.25
Kemudian hasilnya diletakkan di matriks hasil kembali dalam bentuk baris, sehingga
hasilnya (matriks D4) akan sebagai berikut:
5. Atur hasil pada point 4 supaya bagian aproksimasi berkumpul di bagian kiri
dan bagian detail mengumpul di bagian kanan (matriks D5)
Keterangan:
1 0 0 0 1 0 0 0
1 0 0 0 -1 0 0 0
0 1 0 0 0 1 0 0
L*= 0 1 0 0 H* = 0 -1 0 0
0 0 1 0 0 0 1 0
0 0 1 0 0 0 -1 0
0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 -1
2. Untuk setiap baris hasil dekomposisi (matriks D5), kalikan matriks L* dan H*
tersebut dengan bagian dari matriks D5, menjadi:
1 0 0 0 1 0 0 0
1 0 0 0 -1 0 0 0
0 1 0 0 64 0 1 0 0 -7
0 1 0 0 * 41.25 + 0 -1 0 0 * 5.25
0 0 1 0 42.75 0 0 1 0 11.25
0 0 1 0 18.25 0 0 -1 0 7.25
0 0 0 1 0 0 0 1
64 -7 57
64 7 71
= 41.25 + -5.25 = 36
42.75 11.25 54
18.25 -7.25 11
3. Dengan cara yang sama, dilakukan perkalian pada tahap 2 terhadap setiap
kolom dari matriks yang diperoleh pada langkah sebelumnya. Langkah ini
akan menghasilkan kembali citra awal.