Perbandingan Kualitas Citra Hasil Kompresi Metode Run Length Encoding Dengan Transformasi Wavelet Daubechies Pada Citra Digital

LAMPIRAN A : LISTING PROGRAM 1. Form Cover

  function varargout = Cover(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Cover_OpeningFcn, ... 'gui_OutputFcn', @Cover_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 function Cover_OpeningFcn(hObject, eventdata, handles, varargin) handles.Axes1 = imshow('logo.jpg'); handles.output = hObject; guidata(hObject, handles); function varargout = Cover_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function pushbutton1_Callback(hObject, eventdata, handles) Kompresi delete(handles.figure1) function pushbutton2_Callback(hObject, eventdata, handles) Help delete(handles.figure1) function pushbutton3_Callback(hObject, eventdata, handles) close;

  2. Form Kompresi function varargout = Kompresi(varargin)

  gui_Singleton = 1; gui_State = struct( 'gui_Name' , mfilename, ...

  'gui_Singleton' , gui_Singleton, ... 'gui_OpeningFcn' , @Kompresi_OpeningFcn, ... 'gui_OutputFcn' , @Kompresi_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 function Kompresi_OpeningFcn(hObject, eventdata, handles, varargin)

  handles.output = hObject; guidata(hObject, handles);

  

function varargout = Kompresi_OutputFcn(hObject, eventdata, handles)

  varargout{1} = handles.output;

  function btn_ambil_Callback(hObject, eventdata, handles)

  [nama_file,nama_path] = uigetfile({ '*.bmp' , 'File Citra(*.bmp)' ; '*.bmp' , 'File BMP(*.bmp)' ; ...

  '*.*' , 'Semua File(*.*)' }, ... 'Buka File' ); if ~isequal(nama_file,0)

  handles.citra=imread(fullfile(nama_path,nama_file)); guidata(hObject,handles); citra_awal=double(handles.citra); [handles.baris handles.kolom handles.layer]=size(citra_awal); handles.jum=handles.baris*handles.kolom*handles.layer; handles.ukuran = handles.jum / 1000;

  global sizefile_awal;

  sizefile_awal = handles.ukuran; axes(handles.axes_awal); imshow(handles.citra); set(handles.txt_namafile, 'String' ,nama_file); set(handles.txt_sizefile, 'String' ,sizefile_awal);

  else return ; end

  set(handles.btn_kompres_rle, 'Enable' , 'On' ); set(handles.btn_ambil, 'Enable' , 'Off' ); set(handles.btn_reset, 'Enable' , 'On' );

  set(handles.btn_dekompres_daubechies, 'Enable' , 'On' );

  function btn_kompres_rle_Callback(hObject, eventdata, handles) [nama_file_simpan, path_simpan]=uiputfile( ...

  { '*.rle' , 'File kompres(*.rle)' }, ...

  'Menyimpan File Citra Hasil Kompresi BMP' ); global sizefile_awal; global runtime;

  runtime = cputime; image = handles.citra; image_kompres = RunLengthEncoding(image,1); handles.citra = image_kompres; axes(handles.axes_kompresi_rle); imshow(handles.citra); runtime = cputime-runtime; set(handles.txt_rt_kompresi_rle, 'String' ,runtime);

  if ~isequal(nama_file_simpan,0)

  srle=strcat(path_simpan, nama_file_simpan); save (srle, 'image_kompres' ); citra_rle=double(handles.citra); [handles.baris handles.kolom handles.layer]=size(citra_rle); handles.jum_hasil=handles.baris*handles.kolom*handles.layer; handles.ukuran_hasil_rle = handles.jum_hasil / 1000; size_hasil_rle = handles.ukuran_hasil_rle; rasio=100-((size_hasil_rle/sizefile_awal)*100); data_redudansi = 1-(1/(sizefile_awal/size_hasil_rle));

  else return ; end

  set(handles.txt_sizefile_kompresi_rle, 'String' ,size_hasil_rle); set(handles.txt_ratiokompresi_rle, 'String' ,rasio); set(handles.txt_redudansi_rle, 'String' ,data_redudansi); set(handles.btn_dekompres_rle, 'Enable' , 'On' ); set(handles.btn_kompres_rle, 'Enable' , 'Off' );

  

function btn_kompres_daubechies_Callback(hObject, eventdata, handles)

[nama_file_simpan, path_simpan]=uiputfile( ...

  { '*.db' , 'File kompres(*.db)' }, ...

  'Menyimpan File Citra Hasil Kompresi' ); global sizefile_awal; global runtime;

  runtime = cputime; citra_awal = handles.citra; [baris,kolom]=size(citra_awal);

  Matriks_kuantisasi = [16 11 10 16 24 40 51 61; ... 12 12 14 19 26 58 60 55; ... 14 13 16 24 40 57 69 56; ... 14 17 22 29 51 87 80 62; ... 18 22 37 56 68 109 103 77; ... 24 35 55 64 81 104 113 92; ... 49 64 78 87 103 121 120 101; ... 72 92 95 98 112 100 103 99]; citra_proses = zeros(baris,kolom);

  for bx = 1:baris/8 for by = 1:kolom/8

  block = double(citra_awal(bx*8-7:bx*8, by*8-7:by*8))-128; % get

  block, and shift it

  block = db1(block,1); block = round(block ./ Matriks_kuantisasi); disp(block); % quantization citra_proses(bx*8-7:bx*8, by*8-7:by*8) = block;

  end end

  citra_kompres = rlencoding(citra_proses,1); handles.citra = citra_kompres; axes(handles.axes_kompresi_daubechies); imshow(handles.citra); runtime = cputime-runtime; set(handles.txt_rt_kompresi_daubechies, 'String' ,runtime);

  if ~isequal(nama_file_simpan,0)

  srle=strcat(path_simpan, nama_file_simpan); save (srle, 'citra_kompres' ); citra_daubechies=double(handles.citra); [handles.baris handles.kolom handles.layer]=size(citra_daubechies); handles.jum_hasil=handles.baris*handles.kolom*handles.layer; handles.ukuran_hasil_daubechies = handles.jum_hasil / 1000; size_hasil_daubechies = handles.ukuran_hasil_daubechies; rasio=100-((size_hasil_daubechies/sizefile_awal)*100); data_redudansi = 1-(1/(sizefile_awal/size_hasil_daubechies));

  else return ; end

  set(handles.txt_sizefile_kompresi_daubechies, 'String' ,size_hasil_daub echies); set(handles.txt_ratiokompresi_daubechies, 'String' ,rasio); set(handles.txt_redudansi_daubechies, 'String' ,data_redudansi); set(handles.btn_dekompres_daubechies, 'Enable' , 'On' ); set(handles.btn_kompres_daubechies, 'Enable' , 'Off' );

  function btn_dekompres_rle_Callback(hObject, eventdata, handles) [nama_file_rle,nama_path_rle] = uigetfile( ...

  { '*.rle' , 'File kompres(*.rle)' }, ...

  'Buka File RLE' ); if ~isequal(nama_file_rle,0)

  rle=importdata(fullfile(nama_path_rle, nama_file_rle));

  else return ; end global runtime;

  runtime = cputime; image = rle; image_kompres = RunLengthEncoding(image,2); handles.citra = image_kompres; axes(handles.axes_dekompresi_rle); imshow(handles.citra); runtime = cputime-runtime; set(handles.txt_rt_dekompresi_rle, 'String' ,runtime); sImage = getimage(handles.axes_dekompresi_rle); [FileName, PathName] = uiputfile({ '*.bmp' , 'BMP' }, 'Save As' ); pathfile=fullfile(PathName, FileName); imwrite(sImage,pathfile, 'bmp' ); citra_drle=double(handles.citra); [handles.baris handles.kolom handles.layer]=size(citra_drle); handles.jum_hasil_drle=handles.baris*handles.kolom*handles.layer; handles.ukuran_hasil_drle = handles.jum_hasil_drle / 1000; size_hasil_drle = handles.ukuran_hasil_drle; set(handles.txt_sizefile_dekompresi_rle, 'String' ,size_hasil_drle); set(handles.btn_reset, 'Enable' , 'On' ); set(handles.btn_ambil, 'Enable' , 'Off' ); set(handles.btn_kompres_daubechies, 'Enable' , 'On' ); set(handles.btn_dekompres_rle, 'Enable' , 'Off' );

  function btn_dekompres_daubechies_Callback(hObject, eventdata,

  handles) [nama_file_db,nama_path_db] = uigetfile( ... { '*.db' , 'File kompres(*.db)' }, ...

  'Buka File Daubechies' ); if ~isequal(nama_file_db,0)

  db=importdata(fullfile(nama_path_db, nama_file_db));

  else return ; end global runtime;

  runtime = cputime; citra_awal = db; citra_terkompres = rlencoding(citra_awal,2);

  Matriks_kuantisasi = [16 11 10 16 24 40 51 61; ... 12 12 14 19 26 58 60 55; ... 14 13 16 24 40 57 69 56; ... 14 17 22 29 51 87 80 62; ... 18 22 37 56 68 109 103 77; ... 24 35 55 64 81 104 113 92; ... 49 64 78 87 103 121 120 101; ... 72 92 95 98 112 100 103 99]; citra_proses = uint8(zeros(baris,kolom));

  for bx = 1:baris/8 for by = 1:kolom/8

  block = citra_terkompres(bx*8-7:bx*8, by*8-7:by*8); % get block block = block.*Matriks_kuantisasi; %

  dequantization

  block = idb1(block,1); % inverse db block = uint8(block + 128); % shift citra_proses(bx*8-7:bx*8, by*8-7:by*8) = block;

  end end

  handles.citra = citra_proses; citra = handles.citra; axes(handles.axes_dekompresi_daubechies); imshow(handles.citra); runtime = cputime-runtime; set(handles.txt_rt_dekompresi_daubechies, 'String' ,runtime); sImage = getimage(handles.axes_dekompresi_rle); [FileName, PathName] = uiputfile({ '*.bmp' , 'BMP' }, 'Save As' ); pathfile=fullfile(PathName, FileName); imwrite(sImage,pathfile, 'bmp' ); citra_idb=double(handles.citra); [handles.baris handles.kolom handles.layer]=size(citra_idb); handles.jum_hasil_idb=handles.baris*handles.kolom*handles.layer; handles.ukuran_hasil_idb = handles.jum_hasil_idb / 1000; size_hasil_idb = handles.ukuran_hasil_idb; set(handles.txt_sizefile_dekompresi_daubechies, 'String' ,size_hasil_id b); set(handles.btn_dekompres_daubechies, 'Enable' , 'Off' ); set(handles.btn_reset, 'Enable' , 'On' ); set(handles.btn_ambil, 'Enable' , 'Off' );

  function btn_home_Callback(hObject, eventdata, handles)

  Cover delete(handles.figure1)

  function btn_exit_Callback(hObject, eventdata, handles)

  function txt_namafile_Callback(hObject, eventdata, handles) function txt_namafile_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_sizefile_Callback(hObject, eventdata, handles) function txt_sizefile_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_sizefile_kompresi_rle_Callback(hObject, eventdata,

  handles)

  function txt_sizefile_kompresi_rle_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_sizefile_kompresi_daubechies_Callback(hObject,

  eventdata, handles)

  function txt_sizefile_kompresi_daubechies_CreateFcn(hObject,

  eventdata, handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_sizefile_dekompresi_rle_Callback(hObject, eventdata, function txt_sizefile_dekompresi_rle_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_sizefile_dekompresi_daubechies_Callback(hObject,

  eventdata, handles)

  function txt_sizefile_dekompresi_daubechies_CreateFcn(hObject,

  eventdata, handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_rt_kompresi_rle_Callback(hObject, eventdata, handles) function txt_rt_kompresi_rle_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_ratiokompresi_rle_Callback(hObject, eventdata, handles)

function txt_ratiokompresi_rle_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_redudansi_rle_Callback(hObject, eventdata, handles) function txt_redudansi_rle_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_rt_kompresi_daubechies_Callback(hObject, eventdata,

  handles)

  function txt_rt_kompresi_daubechies_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_ratiokompresi_daubechies_Callback(hObject, eventdata,

  handles)

  function txt_ratiokompresi_daubechies_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_redudansi_daubechies_Callback(hObject, eventdata,

  handles)

  function txt_redudansi_daubechies_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function txt_rt_dekompresi_rle_Callback(hObject, eventdata, handles)

function txt_rt_dekompresi_rle_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' ); function txt_rt_dekompresi_daubechies_Callback(hObject, eventdata,

  handles)

  function txt_rt_dekompresi_daubechies_CreateFcn(hObject, eventdata,

  handles)

  if ispc && isequal(get(hObject, 'BackgroundColor' ),

  get(0, 'defaultUicontrolBackgroundColor' )) set(hObject, 'BackgroundColor' , 'white' );

  end function btn_reset_Callback(hObject, eventdata, handles)

  handles.citra=handles.citra([]); axes(handles.axes_awal); imshow(handles.citra); set(handles.btn_ambil, 'Enable' , 'On' ); set(handles.btn_kompres_rle, 'Enable' , 'Off' ); set(handles.btn_dekompres_rle, 'Enable' , 'On' ); set(handles.btn_kompres_daubechies, 'Enable' , 'Off' ); set(handles.btn_dekompres_daubechies, 'Enable' , 'On' ); set(handles.btn_reset, 'Enable' , 'Off' ); set(handles.txt_namafile, 'string' , ' ' ); set(handles.txt_sizefile, 'string' , ' ' ); handles.citra=handles.citra([]); axes(handles.axes_kompresi_rle); imshow(handles.citra); set(handles.txt_sizefile_kompresi_rle, 'string' , ' ' ); set(handles.txt_rt_kompresi_rle, 'string' , ' ' ); set(handles.txt_ratiokompresi_rle, 'string' , ' ' ); set(handles.txt_redudansi_rle, 'string' , ' ' ); handles.citra=handles.citra([]); axes(handles.axes_kompresi_daubechies); imshow(handles.citra); set(handles.txt_sizefile_kompresi_daubechies, 'string' , ' ' ); set(handles.txt_rt_kompresi_daubechies, 'string' , ' ' ); set(handles.txt_ratiokompresi_daubechies, 'string' , ' ' ); set(handles.txt_redudansi_daubechies, 'string' , ' ' ); handles.citra=handles.citra([]); axes(handles.axes_dekompresi_rle); imshow(handles.citra); set(handles.txt_sizefile_dekompresi_rle, 'string' , ' ' ); set(handles.txt_rt_dekompresi_rle, 'string' , ' ' ); handles.citra=handles.citra([]); axes(handles.axes_dekompresi_daubechies); imshow(handles.citra); set(handles.txt_sizefile_dekompresi_daubechies, 'string' , ' ' ); set(handles.txt_rt_dekompresi_daubechies, 'string' , ' ' );

  3. Form Help

  function varargout = Help(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Help_OpeningFcn, ... 'gui_OutputFcn', @Help_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 function Help_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); function varargout = Help_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function pushbutton1_Callback(hObject, eventdata, handles) close; function pushbutton3_Callback(hObject, eventdata, handles) Cover delete(handles.figure1)

  4. Class RunLengthEncoding.m

  function [citrahasil]=RunLengthEncoding(citraawal,pilihan) if (pilihan==1) citrahasil(1:2)=size(citraawal); a=citraawal(1,1); b=0; c=2; for i=1:size(citraawal,1) for j=1:size(citraawal,2) if (citraawal(i,j)==a) b=b+1; else citrahasil(2*c-1)=a; citrahasil(2*c)=b; a=citraawal(i,j); b=1; c=c+1; end end

  elseif (pilihan==2) citrahasil=zeros(citraawal(1:2)); a=1; b=0; for i=2:length(citraawal)/2 for j=1:citraawal(2*i) b=b+1; citrahasil(a,b)=citraawal(2*i-1); if (b==citraawal(2)) a=a+1; b=0; end end end citrahasil=uint8(citrahasil); else error('') end display(citrahasil); end 5.

Class db1.m

  function citrahasil = db1(citraawal, level);

  [baris,kolom] = size(citraawal); count = 0; citrahasil = citraawal;

  while count < level,

  k = 1; j = 1; index = 1;

  while (k <= kolom), for j = 1:baris,

  citraawal1(j, index) = (citraawal(j,k)+citraawal(j,k+1))/2; citraawal1(j, (kolom/2)+(index)) = (citraawal(j,k) - citraawal(j,k+1))/2;

  end

  index = index + 1; k = k + 2;

  end

  index = 1; k = 1; j = 1;

  while (j <= baris), for k = 1:kolom,

  citrahasil(index, k) = (citraawal1(j,k) + citraawal1(j+1,k))/2; citrahasil((baris/2) + (index), k) = (citraawal1(j,k) - citraawal1(j+1, k))/2;

  end

  index = index + 1; j = j + 2;

  end

  baris = baris/2; kolom = kolom/2; count = count+1; citraawal = citrahasil;

  end

  citrahasil = round(citrahasil); 6.

Class idb1.m

  function citraakhir = idb1(citraawal, level); [baris,kolom] = size(citraawal); baris = baris / 2^(level-1); kolom = kolom / 2^(level-1); count = 0; citraakhir = citraawal; citraawal1 = citraawal; while count < level index = 1; j = 1; k = 1; while j < baris, for k = 1:kolom, citraawal1(j,k) = (citraawal(index,k) + citraawal(index+baris/2,k)); citraawal1(j+1,k) = (citraawal(index,k) - citraawal(index+baris/2,k)); end j = j+2; index = index+1; end k = 1; j = 1; index = 1; while k <= kolom, for j = 1:baris, citraakhir(j,k) = (citraawal1(j,index) + citraawal1(j, index+kolom/2)); citraakhir(j, k+1) = (citraawal1(j,index) - citraawal1(j, index+kolom/2)); end k = k + 2; index = index+1; end count = count+1; baris = baris*2; kolom = kolom*2; citraawal = citraakhir; end citraakhir = round(citraakhir);

  function [citrahasil]=rlencodcitraawalg(citraawal,pilihan) if (pilihan==1) citrahasil(1:2)=size(citraawal); a=citraawal(1,1); b=0; c=2; for i=1:size(citraawal,1) for j=1:size(citraawal,2) if (citraawal(i,j)==a) b=b+1; else citrahasil(2*c-1)=a; citrahasil(2*c)=b; a=citraawal(i,j); b=1; c=c+1; end end end elseif (pilihan==2) citrahasil=zeros(citraawal(1:2)); a=1; b=0; for i=2:length(citraawal)/2 for j=1:citraawal(2*i) b=b+1; citrahasil(a,b)=citraawal(2*i-1); if (b==citraawal(2)) a=a+1; b=0; end end end citrahasil=double(citrahasil); else error('') end display(citrahasil); end