aaa

Berusaha yang TERBAIK

Kamis, 22 November 2012

WATERMARKING MENGGUNAKAN MATLAB


Disusun oleh Lili Andini (55409680) dan Maryam Dwi (54409759)

Telah dibahas pada posingan sebelumnya tentang segala sesuatu tentang watermarking. Membahas tentang apa itu watermarking, tentang watermarking digital, tentang penyisipan watermarking, dan lain-lain. Watermarking merupakan suatu bentuk dari steganography (Ilmu yang mempelajari bagaimana menyembunyikan suatu data pada data yang lain), dalam mempelajari teknik-teknik bagaimana penyimpanan suatu data (digital) kedalam data host digital yang lain (Istilah host digunakan untuk data / sinyal digital yang ditumpangi), tetapi orang lain tidak menyadari kehadiran adanya data tambahan pada data host-nya. Pada postingan kali ini akan dibahas tentang MATLAB dan langkah-langkah pengaplikasian watermarking dengan menggunakan Matlab.



A.     Definisi MATLAB
MATLAB adalah sebuah bahasa dengan (high-performance) kinerja tinggi untuk komputasi masalah teknik. Matlab mengintegrasikan komputasi, visualisasi, dan pemrograman dalam suatu model yang sangat mudah untuk dipakai dimana masalah-masalah dan penyelesaiannya diekspresikan dalam notasi matematika yang familiar. Penggunaan Matlab meliputi bidang-bidang :
  •   Matematika dan Komputasi
  • Pembentukan Algorithm
  •   Akusisi Data
  •  Pemodelan, simulasi, dan pembuatan prototype
  •     Analisa Data, eksplorasi, dan visualisasi
  •   Grafik Keilmuan dan bidang Rekayasa


Matlab merupakan suatu sistem interaktif yang memiliki elemen data dalam suatu array sehingga tidak lagi kita pusingkan dengan masalah dimensi. Hal ini memungkinkan kita untuk memecahkan banyak masalah teknis yang terkait dengan komputasi, khususnya yang berhubungan dengan matrix dan formulasi vektor, yang mana masalah tersebut merupakan momok apabila kita harus menyelesaikannya dengan menggunakan bahasa level rendah seperti Pascall, C dan Basic.
Nama Matlab merupakan singkatan dari Matrix Laboratory. MatLab pada awalnya ditulis untuk memudahkan akses perangkat lunak matrik yang telah dibentuk oleh LINPACK dan EISPACK.
Fitur-fitur Matlab sudah banyak dikembangkan, dan lebih dikenal dengan nama toolbox. Toolbox merupakan kumpulan dari fungsi-fungsi Matlab (M-files) yang telah dikembangkan ke suatu lingkungan kerja Matlab untuk memecahkan masalah dalam kelas particular. Area-area yang sudah bisa dipecahkan dengan toolbox saat ini meliputi pengolahan sinyal, system control, neural networks, fuzzy logic, wavelets, dan lain-lain.

B.     Kelengkapan pada Sistem Matlab
Sebagai sebuah sistem, Matlab tersusun dari 5 bagian utama, yaitu :
  • Development Environment. Merupakan sekumpulan perangkat dan fasilitas yang membantu untuk menggunakan fungsi-fungsi dan file-file Matlab. Beberapa perangkat ini merupakan sebuah graphical user interface (GUI). Termasuk didalamnya adalah Matlab desktop dan Command Window, command history, sebuah editor dan debugger, dan browsers untuk melihat help, workspace, files, dan search path.
  • MATLAB Mathematical Function Library. Merupakan sekumpulan algoritma komputasi mulai dari fungsi-fungsi dasar sepertri: sum, sin, cos, dan complex arithmetic, sampai dengan fungsi-fungsi yang lebih kompek seperti matrix inverse, matrix eigenvalues, Bessel functions, dan fast Fourier transforms.
  • MATLAB Language. Merupakan suatu high-level matrix/array language dengan control flow statements, functions, data structures, input/output, dan fitur-fitur object-oriented programming. Ini memungkinkan untuk melakukan kedua hal baik "pemrograman dalam lingkup sederhana " untuk mendapatkan hasil yang cepat, dan "pemrograman dalam lingkup yang lebih besar" untuk memperoleh hasil-hasil dan aplikasi yang komplek.
  •  Graphics. MATLAB memiliki fasilitas untuk menampilkan vector dan matrices sebagai suatu grafik. Didalamnya melibatkan high-level functions (fungsi-fungsi level tinggi) untuk visualisasi data dua dikensi dan data tiga dimensi, image processing, animation, dan presentation graphics. Ini juga melibatkan fungsi level rendah yang memungkinkan bagi anda untuk membiasakan diri untuk memunculkan grafik mulai dari benutk yang sederhana sampai dengan tingkatan graphical user interfaces pada aplikasi MATLAB anda.
  • MATLAB Application Program Interface (API). Merupakan suatu library yang memungkinkan program yang telah anda tulis dalam bahasa C dan Fortran mampu berinterakasi dengan MATLAB. Ini melibatkan fasilitas untuk pemanggilan routines dari MATLAB (dynamic linking), pemanggilan MATLAB sebagai sebuah computational engine, dan untuk membaca dan menuliskan MAT-files.

C.      Langkah pembuatan watermarking menggunakan MATLAB

Setelah mengenal teori tentang MATLAB dan Watermarking, sekarang mari beranjak kepada tahapan pembuatan aplikasi watermarking. Untuk pembuatan aplikasi ini, kami memilih menggunakan MATLAB 7.1 dan untuk membuatnya, ada beberapa tahap yang harus dilakukan.
      Double-click pada shortcut Matlab. Lalu akan muncul tampilan awal matlab seperti dibawah ini.


      Buat desain GUI sederhana untuk aplikasi watermarking ini dengan menggunakan MATLAB. Caranya adalah, klik New à GUI

      Pilih Blank GUI (default) pada jendela GUIDE Quick Start

      Kemudian akan muncul sebuah jendela baru seperti di bawah ini


      Klik gambar kotak bertuliskan “txt” yang ada pada toolbar yang terdapat di samping kiri jendela tersebut. Kemudian, ketik kata-kata yang diinginkan pada bagian string yang terdapat dalam jendela property inspector.

      Tutup jendela Property Inspector yang tadi dipanggil untuk mendesain yang sebelumnya. Kemudian, klik tool "ok" yang terdapat pada toolbar yang ada di toolbar samping kiri. Lakukan hal yang sama, yaitu edit bagian string pada Property Inspector. Hanya saja, beri nama yang berbeda, yaitu "Color Watermark".

      Buatlah push button yang kedua dengan melakukan hal yang sama dengan nomor 5. Ganti string dengan nama "Gray Watermark".

 Berikut ini adalah GUI pertama yang berhasil dibuat. Simpanlah dengan nama WatermarkMain.fig

  Kemudian, ketiklah kode program untuk WatermarkMain.fig. Berikut ini adalah kode program untuk WatermarkMain.fig. Jangan lupa, simpanlah kode program berikut dengan nama WatermarkMain.m.

function varargout = WatermarkMain(varargin)
% WATERMARKMAIN M-file for WatermarkMain.fig
% WATERMARKMAIN, by itself, creates a new WATERMARKMAIN or raises the existing
% singleton*.
%
% H = WATERMARKMAIN returns the handle to a new WATERMARKMAIN or the handle to
% the existing singleton*.
%
% WATERMARKMAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WATERMARKMAIN.M with the given input arguments.
%
% WATERMARKMAIN('Property','Value',...) creates a new WATERMARKMAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before WatermarkMain_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to WatermarkMain_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help WatermarkMain

% Last Modified by GUIDE v2.5 04-Apr-2009 13:19:31

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @WatermarkMain_OpeningFcn, ...
'gui_OutputFcn', @WatermarkMain_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before WatermarkMain is made visible.
function WatermarkMain_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to WatermarkMain (see VARARGIN)

% Choose default command line output for WatermarkMain
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes WatermarkMain wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = WatermarkMain_OutputFcn(hObject, eventdata, handles) 
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
ColorWatermarking
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
GrayWatermarking
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

  Buatlah GUI kedua untuk "Color Watermarking" dan GUI ketiga untuk "Gray Watermarking" dengan langkah-langkah yang sama dengan pembuatan GUI "Digital Watermarking", yaitu dengan mengikuti langkah 1 hingga 8 dan buatlah tampiilan GUI tersebut menjadi seperti ini. Simpan masing-masing GUI dengan nama ColorWatermarking.fig dan GrayWatermarking.fig


  Buatlah M-File baru untuk membuat kode program bagi ColorWatermark.fig. Ketiklah program di bawah ini dan simpanlah dengan nama ColorWatermarking.m.
function varargout = ColorWatermarking(varargin)
% COLORWATERMARKING M-file for ColorWatermarking.fig
% COLORWATERMARKING, by itself, creates a new COLORWATERMARKING or raises the existing
% singleton*.
%
% H = COLORWATERMARKING returns the handle to a new COLORWATERMARKING or the handle to
% the existing singleton*.
%
% COLORWATERMARKING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in COLORWATERMARKING.M with the given input arguments.
%
% COLORWATERMARKING('Property','Value',...) creates a new COLORWATERMARKING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ColorWatermarking_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ColorWatermarking_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help ColorWatermarking

% Last Modified by GUIDE v2.5 04-Apr-2009 13:26:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ColorWatermarking_OpeningFcn, ...
'gui_OutputFcn', @ColorWatermarking_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before ColorWatermarking is made visible.
function ColorWatermarking_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ColorWatermarking (see VARARGIN)

% Choose default command line output for ColorWatermarking
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ColorWatermarking wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ColorWatermarking_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
wm
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
iwm
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
12. Berikut ini adalah kode program untuk GrayWatermarking.fig. Sama halnya dengan ColorWatermarking. Untuk memulainya, klik New >> M-File dan ketikkan kode program di bawah ini serta simpan dengan nama GrayWatermarking.m.
function varargout = GrayWatermarking(varargin)
% GRAYWATERMARKING M-file for GrayWatermarking.fig
% GRAYWATERMARKING, by itself, creates a new GRAYWATERMARKING or raises the existing
% singleton*.
%
% H = GRAYWATERMARKING returns the handle to a new GRAYWATERMARKING or the handle to
% the existing singleton*.
%
% GRAYWATERMARKING('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GRAYWATERMARKING.M with the given input arguments.
%
% GRAYWATERMARKING('Property','Value',...) creates a new GRAYWATERMARKING or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GrayWatermarking_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GrayWatermarking_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help GrayWatermarking

% Last Modified by GUIDE v2.5 04-Apr-2009 13:26:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GrayWatermarking_OpeningFcn, ...
'gui_OutputFcn', @GrayWatermarking_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GrayWatermarking is made visible.
function GrayWatermarking_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GrayWatermarking (see VARARGIN)

% Choose default command line output for GrayWatermarking
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GrayWatermarking wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GrayWatermarking_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
wm_gray
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
iwm_gray
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
13. Buatlah M-File lainnya seperti get_xy_point.m, iwm.m, iwm_gray.m, wm.m dan wm_gray.m. Berikut adalah kode programnya.
get_xy_point.m
function [pointx, pointy, pointval] = get_xy_point(input_img)

%function return_mat = get_xy_point(input_img)

pointx=0;
pointy=0;
pointval=0;

input_img_size=size(input_img);

input_img_size_height=(input_img_size(1));
input_img_size_width=(input_img_size(2));

input_img_size_height=uint16(input_img_size_height);
input_img_size_width=uint16(input_img_size_width);

%--------------------no need to resize image since already done in iwm
%--------------------ie:divide by 8 and multiply by 8
%--------------------from_height=25% of height
%--------------------from_width=25% of width
%--------------------8*0.25=2;
from_height=0.25*input_img_size_height;
from_width=0.25*input_img_size_height;

for i=from_height:input_img_size_height
for j=from_width:input_img_size_width
if(input_img(i,j,1)>pointval)

pointval=input_img(i,j,1);
pointx=i;
pointy=j;

end
end
end

%----------------------------------------comment started
%for i=1:input_img_size_height
% for j=1:input_img_size_height
% if( ((input_img_size_height+i-j)<=input_img_size_height) && j<=input_img_size_width) % img(input_img_size_height+i-j,j)=1; % end % end %end %for i=1:input_img_size_height % for j=1:input_img_size_width % if( (input_img(i,j)>pointval) && (img(i,j)==1) )
% pointval=input_img(i,j);
% pointx=i;
% pointy=j;
% end
% end
%end
%----------------------------------------comment ended

return_mat(1)=pointx;
return_mat(2)=pointy;
return_mat(3)=pointval;
iwm.m
clc
clear
% input image: watermarked.bmp
% ouptput image: gotlogo.bmp
%----------------------------------------------modified start
% input watermarked image string:src_file
% input watermarked image:src

% logo image string to save logo:logo_file
% logo image:logo

%----------------------------------------------modified end


%----------modified on 18032009 start

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Watermarked Image File');
src_file=cat(2,pathname,filename);


[filename, pathname] = ...
uiputfile({'*.jpg';'*.jpeg';'*.bmp'},'Save The Regained Logo Image File As');
logo_file=cat(2,pathname,filename);


src=imread(src_file);
%----------modified on 18032009 end


%----------modified comment on 18032009 start
%----------remove below comment to undo

%src_file=input('Enter watermarked file name %','s');
%src=imread(src_file);
%logo_file=input('Enter file name to save the got logo %','s');

%----------remove above comment to undo
%----------modified comment on 18032009 end

%---------------------------------------------source start
src_size=size(src);

src_size_height=(src_size(1));
src_size_width=(src_size(2));

%---------------------------------src double to int
src_size_height_int=uint16(src_size_height);
src_size_width_int=uint16(src_size_width);

%---------------------------------step necessary to resize image start
%---------------------------------to get good logo
%---------------------------------65/8=8 & 8*8=64
%----------------------------ie:divide by 8 and multiply by 8
src_size_height_int=src_size_height_int/8;
src_size_width_int=src_size_width_int/8;

src_size_height_int=src_size_height_int*8;
src_size_width_int=src_size_width_int*8;

%---------------------------------to double

src_size_height=double(src_size_height_int);
src_size_width=double(src_size_width_int);

src=imresize(src,[src_size_height src_size_width]);

%---------------------------------step necessary to resize image end


%---------------------------------back to int
%---------------------------------inserted comment for testing start
%src_size_height_int=uint16(src_size_height);
%src_size_width_int=uint16(src_size_width);
%---------------------------------inserted comment for testing end

imview(src);

dct_src(:,:,1)=dct2(src(:,:,1));
dct_src(:,:,2)=dct2(src(:,:,2));
dct_src(:,:,3)=dct2(src(:,:,3));

imview(dct_src);
%-----------------------------------------------new
[pointx,pointy,pointval]=get_xy_point(dct_src);
%since loop x,y starts from 1 hence first decrement pointx & pointy by 1
pointx=pointx-1;
pointy=pointy-1;

%-----------------------------------------------new
%-------------------------temporary output

%img_temp=uint8(dct_src);
%imwrite(img_temp,'temp_90.bmp');



%-------------------------------initial logo setup
%-------------------------------logo size[h,w]= 1/8*size[h,w]
logo_size_height=double(src_size_height/8);
logo_size_width=double(src_size_width/8);


%------------------------get dct of logo from dct of src at 50% fixed start


%------------------------remove the following comment from block to undo
%------------------------comment start date 16032009(modification start)
%for x=1:logo_size_height
% for y=1:logo_size_width
% dct_logo(x,y,1)=dct_src((x+(src_size_height_int/2)),(y+(src_size_width_int/2)),1);
% dct_logo(x,y,2)=dct_src((x+(src_size_height_int/2)),(y+(src_size_width_int/2)),2);
% dct_logo(x,y,3)=dct_src((x+(src_size_height_int/2)),(y+(src_size_width_int/2)),3);
% end
%end
%------------------------comment end date 16032009(modification end)

%------------------------comment the following comment from block to undo
%(modification start)
for x=1:logo_size_height
for y=1:logo_size_width
if( src_size_height> (y+pointy) & src_size_width> (x+pointx) )
dct_logo(x,y,1)=dct_src((x+pointx),(y+pointy),1);%16032009
dct_logo(x,y,2)=dct_src((x+pointx),(y+pointy),2);%16032009
dct_logo(x,y,3)=dct_src((x+pointx),(y+pointy),3);%16032009
else
dct_logo(x,y,1)=0;%16032009
dct_logo(x,y,2)=0;%16032009
dct_logo(x,y,3)=0;%16032009
end
end
end
%(modification end)

%------------------------get dct of logo from dct of src at 50% fixed end

%for x=1:100
% for y=1:100
% dct_logo(x,y,1)=dct_read_wm(x+500,y+500,1);
% dct_logo(x,y,2)=dct_read_wm(x+500,y+500,2);
% dct_logo(x,y,3)=dct_read_wm(x+500,y+500,3);
% end
%end

imview(dct_logo);

%----------------to get logo image
idct_logo(:,:,1)=idct2(dct_logo(:,:,1));
idct_logo(:,:,2)=idct2(dct_logo(:,:,2));
idct_logo(:,:,3)=idct2(dct_logo(:,:,3));

idct_logo=uint8(idct_logo);

imview(idct_logo);
imwrite(idct_logo,logo_file);
iwm_gray.m
clc
clear
% input image: watermarked.bmp
% ouptput image: gotlogo.bmp
%----------------------------------------------modified start
% input watermarked image string:src_file
% input watermarked image:src

% logo image string to save logo:logo_file
% logo image:logo

%----------------------------------------------modified end


%----------modified on 18032009 start

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Watermarked Image File');
src_file=cat(2,pathname,filename);


[filename, pathname] = ...
uiputfile({'*.jpg';'*.jpeg';'*.bmp'},'Save The Regained Logo Image File As');
logo_file=cat(2,pathname,filename);


src=imread(src_file);
%----------modified on 18032009 end


%----------modified comment on 18032009 start
%----------remove below comment to undo

%src_file=input('Enter watermarked file name %','s');
%src=imread(src_file);
%logo_file=input('Enter file name to save the got logo %','s');

%----------remove above comment to undo
%----------modified comment on 18032009 end

%---------------------------------------------source start
src_size=size(src);

src_size_height=(src_size(1));
src_size_width=(src_size(2));

%---------------------------------src double to int
src_size_height_int=uint16(src_size_height);
src_size_width_int=uint16(src_size_width);

%---------------------------------step necessary to resize image start
%---------------------------------to get good logo
%---------------------------------65/8=8 & 8*8=64
%----------------------------ie:divide by 8 and multiply by 8
src_size_height_int=src_size_height_int/8;
src_size_width_int=src_size_width_int/8;

src_size_height_int=src_size_height_int*8;
src_size_width_int=src_size_width_int*8;

%---------------------------------to double

src_size_height=double(src_size_height_int);
src_size_width=double(src_size_width_int);

src=imresize(src,[src_size_height src_size_width]);

%---------------------------------step necessary to resize image end


%---------------------------------back to int
%---------------------------------inserted comment for testing start
%src_size_height_int=uint16(src_size_height);
%src_size_width_int=uint16(src_size_width);
%---------------------------------inserted comment for testing end

imview(src);

dct_src(:,:,1)=dct2(src(:,:));

imview(dct_src);
%-----------------------------------------------new
[pointx,pointy,pointval]=get_xy_point(dct_src);
%since loop x,y starts from 1 hence first decrement pointx & pointy by 1
pointx=pointx-1;
pointy=pointy-1;

%-----------------------------------------------new
%-------------------------temporary output

%img_temp=uint8(dct_src);
%imwrite(img_temp,'temp_90.bmp');



%-------------------------------initial logo setup
%-------------------------------logo size[h,w]= 1/8*size[h,w]
logo_size_height=double(src_size_height/8);
logo_size_width=double(src_size_width/8);


%------------------------get dct of logo from dct of src at 50% fixed start


%------------------------remove the following comment from block to undo
%------------------------comment start date 16032009(modification start)
%for x=1:logo_size_height
% for y=1:logo_size_width
% dct_logo(x,y)=dct_src((x+(src_size_height_int/2)),(y+(src_size_width_int/2)));
% end
%end
%------------------------comment end date 16032009(modification end)

%------------------------comment the following comment from block to undo
%(modification start)
for x=1:logo_size_height
for y=1:logo_size_width
if( src_size_height> (y+pointy) & src_size_width> (x+pointx) )
dct_logo(x,y)=dct_src((x+pointx),(y+pointy));%16032009
else
dct_logo(x,y)=0;%16032009
end
end
end
%(modification end)

%------------------------get dct of logo from dct of src at 50% fixed end

%for x=1:100
% for y=1:100
% dct_logo(x,y)=dct_read_wm(x+500,y+500);
% end
%end

imview(dct_logo);

%----------------to get logo image
idct_logo(:,:,1)=idct2(dct_logo(:,:));

idct_logo=uint8(idct_logo);

imview(idct_logo);
imwrite(idct_logo,logo_file);
wm.m
clc
clear

% input image: 800800.bmp
% logo image: 100100logo.bmp
% ouptput image: watermarked.bmp

%----------------------------------------------modified start
% input image string:src_file
% input image :src

% logo image string:logo_file
% logo image :logo

% output image string:dest_file
% output image :dest
%----------------------------------------------modified end
%----------modified on 18032009 start
filename=0;
pathname=0;
%while()

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Source Image File');
src_file=cat(2,pathname,filename);

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Logo Image File');
logo_file=cat(2,pathname,filename);

[filename, pathname] = ...
uiputfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Destination Image File');
dest_file=cat(2,pathname,filename);
%end

%----------modified on 18032009 end



%----------modified comment on 18032009 start
%----------remove below comment to undo

%src_file=input('Enter source file name:','s');
%logo_file=input('Enter logo file name:','s');
%dest_file=input('Enter destination file name:','s');

%----------remove above comment to undo
%----------modified comment on 18032009 end

%---------------------------------------------source start

src=imread(src_file);
%src=imread('800800.bmp');
imview(src);

%---------------------------------steps necessary to resize image
src_size=size(src);

src_size_height=(src_size(1));
src_size_width=(src_size(2));

%---------------------------------src double to int
src_size_height_int=uint16(src_size_height);
src_size_width_int=uint16(src_size_width);

%---------------------------------65/8=8 & 8*8=64
%----------------------------ie:divide by 8 and multiply by 8
src_size_height_int=src_size_height_int/8;
src_size_width_int=src_size_width_int/8;

src_size_height_int=src_size_height_int*8;
src_size_width_int=src_size_width_int*8;

%---------------------------------size back to double

src_size_height=double(src_size_height_int);
src_size_width=double(src_size_width_int);

%src_size_height=src_size_height_int;hhhhhhhhhhhhhhhhhhhhhhhhhhhhh
%src_size_width=src_size_width_int;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

%---------------------------------resize image to no divisible by 8
src=imresize(src,[src_size_height src_size_width]);

%---------------------------------back to int

%---------------------------------inserted comment for testing start
%src_size_height_int=uint16(src_size_height);
%src_size_width_int=uint16(src_size_width);
%---------------------------------inserted comment for testing end



dct_src(:,:,1)=dct2(src(:,:,1));
dct_src(:,:,2)=dct2(src(:,:,2));
dct_src(:,:,3)=dct2(src(:,:,3));

imview(dct_src);

logo=imread(logo_file);
%logo=imread('100100logo.bmp');

imview(logo);

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------------------------steps necessary to resize logo

logo_size_height=(src_size_height/8);
logo_size_width=(src_size_width/8);

%logo_size=[logo_size_height logo_size_width_int 3];

logo=imresize(logo,[logo_size_height logo_size_width]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%

dct_logo(:,:,1)=dct2(logo(:,:,1));
dct_logo(:,:,2)=dct2(logo(:,:,2));
dct_logo(:,:,3)=dct2(logo(:,:,3));

imview(dct_logo);
%----------------------------add dct of logo to dct of src at 50% fixed start

%----------------------------comment start at 04042009
%for x=1:logo_size_height
% for y=1:logo_size_width
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),1)=dct_logo(x,y,1);
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),2)=dct_logo(x,y,2);
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),3)=dct_logo(x,y,3);
% end
%end
%----------------------------comment start at 04042009

%----------------------------modify start at 04042009
src_size_height_int_by_2=src_size_height_int/2;
src_size_width_int_by_2=src_size_width_int/2;

for x=1:logo_size_height
for y=1:logo_size_width
dct_src(x+(src_size_height_int_by_2),y+(src_size_width_int_by_2),1)=dct_logo(x,y,1);
dct_src(x+(src_size_height_int_by_2),y+(src_size_width_int_by_2),2)=dct_logo(x,y,2);
dct_src(x+(src_size_height_int_by_2),y+(src_size_width_int_by_2),3)=dct_logo(x,y,3);
end
end
%----------------------------modify end at 04042009


%----------------------------add dct of logo to dct of src at 50% fixed end

imview(dct_src);

idct_src(:,:,1)=idct2(dct_src(:,:,1));
idct_src(:,:,2)=idct2(dct_src(:,:,2));
idct_src(:,:,3)=idct2(dct_src(:,:,3));

idct_src=uint8(idct_src);

imview(idct_src);

imwrite(idct_src,dest_file);
%imwrite(idct_src,'watermarked.bmp');
wm_gray.m
clc
clear

% input image: 800800.bmp
% logo image: 100100logo.bmp
% ouptput image: watermarked.bmp

%----------------------------------------------modified start
% input image string:src_file
% input image :src

% logo image string:logo_file
% logo image :logo

% output image string:dest_file
% output image :dest
%----------------------------------------------modified end
%----------modified on 18032009 start
filename=0;
pathname=0;
%while()

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Source Image File');
src_file=cat(2,pathname,filename);

[filename, pathname] = ...
uigetfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Logo Image File');
logo_file=cat(2,pathname,filename);

[filename, pathname] = ...
uiputfile({'*.jpg';'*.jpeg';'*.bmp'},'Select Destination Image File');
dest_file=cat(2,pathname,filename);
%end

%----------modified on 18032009 end



%----------modified comment on 18032009 start
%----------remove below comment to undo

%src_file=input('Enter source file name:','s');
%logo_file=input('Enter logo file name:','s');
%dest_file=input('Enter destination file name:','s');

%----------remove above comment to undo
%----------modified comment on 18032009 end

%---------------------------------------------source start

src=imread(src_file);

src=rgb2gray(src);%-----------********************BW

%src=imread('800800.bmp');
imview(src);

%---------------------------------steps necessary to resize image
src_size=size(src);

src_size_height=(src_size(1));
src_size_width=(src_size(2));

%---------------------------------src double to int
src_size_height_int=uint16(src_size_height);
src_size_width_int=uint16(src_size_width);

%---------------------------------65/8=8 & 8*8=64
%----------------------------ie:divide by 8 and multiply by 8
src_size_height_int=src_size_height_int/8;
src_size_width_int=src_size_width_int/8;

src_size_height_int=src_size_height_int*8;
src_size_width_int=src_size_width_int*8;

%---------------------------------size back to double

src_size_height=double(src_size_height_int);
src_size_width=double(src_size_width_int);

%src_size_height=src_size_height_int;hhhhhhhhhhhhhhhhhhhhhhhhhhhhh
%src_size_width=src_size_width_int;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

%---------------------------------resize image to no divisible by 8
src=imresize(src,[src_size_height src_size_width]);

%---------------------------------back to int

%---------------------------------inserted comment for testing start
%src_size_height_int=uint16(src_size_height);
%src_size_width_int=uint16(src_size_width);
%---------------------------------inserted comment for testing end



dct_src(:,:)=dct2(src(:,:));

imview(dct_src);

logo=imread(logo_file);

logo=rgb2gray(logo);%-----------********************BW

%logo=imread('100100logo.bmp');

imview(logo);

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---------------------------------steps necessary to resize logo

logo_size_height=(src_size_height/8);
logo_size_width=(src_size_width/8);

%logo_size=[logo_size_height logo_size_width_int 3];

logo=imresize(logo,[logo_size_height logo_size_width]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%

dct_logo(:,:)=dct2(logo(:,:));

imview(dct_logo);
%----------------------------add dct of logo to dct of src at 50% fixed start

%----------------------------comment start at 04042009
%for x=1:logo_size_height
% for y=1:logo_size_width
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),1)=dct_logo(x,y,1);
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),2)=dct_logo(x,y,2);
% dct_src(x+(src_size_height_int/2),y+(src_size_width_int/2),3)=dct_logo(x,y,3);
% end
%end
%----------------------------comment start at 04042009

%----------------------------modify start at 04042009
src_size_height_int_by_2=src_size_height_int/2;
src_size_width_int_by_2=src_size_width_int/2;

for x=1:logo_size_height
for y=1:logo_size_width
dct_src(x+(src_size_height_int_by_2),y+(src_size_width_int_by_2))=dct_logo(x,y);
end
end
%----------------------------modify end at 04042009


%----------------------------add dct of logo to dct of src at 50% fixed end

imview(dct_src);

idct_src(:,:)=idct2(dct_src(:,:));

idct_src=uint8(idct_src);

imview(idct_src);

imwrite(idct_src,dest_file);
%imwrite(idct_src,'watermarked.bmp');
  Jika semua kode program sudah diketikkan, Run program. Pada saat proses Running, aplikasi atau program yang dibuat tadi akan mengeluarkan beberapa jendela baru. Di antaranya terdapat jendela OverView yang merupakan jendela untu View image yang keluar dengan lebih jelas. Jangan lupa, untuk menaruh foto yang akan diproses di folder work di mana file .m dan file .fig tersimpan. Berikut ini adalah contoh output tanpa disertakan jendela OverView.


2 komentar:

  1. kita juga punya nih artikel mengenai 'MATLAB', silahkan dikunjungi dan dibaca , berikut linknya
    http://repository.gunadarma.ac.id/bitstream/123456789/1229/1/50407547.pdf
    terimakasih

    BalasHapus
  2. Assalamualaikum, mbak Uwie Sulistya, saya ada project tugas akhir untuk membuat simulasi watermark DWT, Hybrid DWT-DCT,Hybrid DWT-DFT, mohon menghubungi saya Iman by WA 087878334403 atau mail, im_firman@yahoo.com kita sepakati dulu harganya

    salam

    ImanF

    BalasHapus