2. Form JPEG - Appendix (685.5Kb)

LISTING PROGRAM

  1. Form Awal function varargout = awal(varargin)

function awal_OpeningFcn(hObject, eventdata, handles, varargin)

  handles.output = hObject; guidata(hObject, handles); axes(handles.axes_logo); img = imread( 'logo.png' ); image(img); grid off ; axis off ;

  

function varargout = awal_OutputFcn(hObject, eventdata, handles)

  varargout{1} = handles.output;

  function jpeg_button_Callback(hObject, eventdata, handles)

  jpeg % membuka figure jpeg (jpeg.fig) delete(handles.figure1);

  function bwt_button_Callback(hObject, eventdata, handles)

  bwt % membuka figure bwt (bwt.fig) delete(handles.figure1);

  function help_button_Callback(hObject, eventdata, handles)

  bantuan % membuka figure bantuan (bantuan.fig) delete(handles.figure1);

  function about_button_Callback(hObject, eventdata, handles)

  programmer % membuka figure profil programmer (programmer.fig) delete(handles.figure1);

  function exit_button_Callback(hObject, eventdata, handles) selection = questdlg( 'Keluar?' , ...

  'Konfirmasi' , 'Ya' , 'Tidak' , 'Ya' ); if strcmp(selection, 'Tidak' ) return ; end

  delete(handles.figure1)

  2. Form JPEG function varargout = jpeg(varargin)

function jpeg_OpeningFcn(hObject, eventdata, handles, varargin)

  handles.output = hObject; guidata(hObject, handles); A = imread( 'Awal.jpg' ); axes(handles.axes_asli); imshow(A); axes(handles.axes_hasil); imshow(A); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); function varargout = jpeg_OutputFcn(hObject, eventdata, handles)

  varargout{1} = handles.output;

  function btn_buka_Callback(hObject, eventdata, handles) global input_citra; global img;

  set(handles.text_proses, 'String' , 'Wait...' ); pause(0.1); [filename, pathname] = uigetfile({ '*.bmp' }, 'Buka File Citra' );

  if ~isequal (filename,0) && ~isequal (pathname,0)

  [pathstr,name,ext] = fileparts([pathname filename]);

  if ext == '.bmp'

  input_citra = fullfile(pathname,filename); info = imfinfo(fullfile(pathname,filename)); size_file = info.FileSize/1000; str = num2str(size_file, '%1.1f Kb' ); img = imread(input_citra); axes(handles.axes_asli); imshow(img); A = imread( 'Awal.jpg' ); axes(handles.axes_hasil); imshow(A); dim3 = size(img,3);

  if (dim3 > 1)

  lihat_citra

  end

  edit_hasil = ' ' ; edit_ukuran = 'Ukuran File Citra' ; set(handles.edit_citra_hasil, 'String' ,edit_hasil); set(handles.size2, 'String' ,edit_ukuran); set(handles.edit1, 'String' ,edit_hasil); set(handles.edit2, 'String' ,edit_hasil); set(handles.edit3, 'String' ,edit_hasil); set(handles.edit_citra_asli, 'String' ,filename); set(handles.size1, 'String' ,str); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1);

  else

  errordlg( 'Sistem hanya membaca citra dengan format bitmap

  (*.bmp)' );

  set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1);

  return ; end else

  set(handles.text_proses, 'String' , 'Ready' ); pause(0.1);

  end function btn_kompresi_Callback(hObject, eventdata, handles) global input_citra; runtime = cputime; set(handles.text_proses, 'String' , 'Wait...' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1); image = imread(input_citra); assignin( 'base' , 'citraAsli' ,image) q = 1; [img_kompres] = im2jpeg(image, q); runtime = cputime - runtime; [ratio] = imratio(image,img_kompres); set(handles.edit2, 'String' ,ratio); str = num2str(runtime, '%1.2f s' ); set(handles.edit3, 'String' ,str); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'On' ); pause(0.1);

  function btn_dekompresi_Callback(hObject, eventdata, handles)

  runtime = cputime; set(handles.text_proses, 'String' , 'Wait...' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1); [image_reconst] = jpeg2im; runtime = cputime - runtime; assignin( 'base' , 'citraHasil' ,image_reconst) str = num2str(runtime, '%1.2f s' ); set(handles.edit1, 'String' ,str); axes(handles.axes_hasil); imshow(image_reconst); file = 'C:\Users\Yudha\Documents\MATLAB\Skripsi\jpeg\img

  dekompres\citraDekompres.jpeg' ;

  S = getimage(handles.axes_hasil); imwrite(S, file); info = imfinfo(file); size_file_hasil = info.FileSize/1000; str1 = num2str(size_file_hasil, '%1.1f Kb' ); set(handles.edit_citra_hasil, 'String' , 'citraDekompres.jpeg' ); set(handles.size2, 'String' ,str1); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'On' ); pause(0.1); function btn_keluar_Callback(hObject, eventdata, handles) selection = questdlg( 'Kembali ke menu awal?' , ...

  'Konfirmasi' , 'Ya' , 'Tidak' , 'Ya' ); if strcmp(selection, 'Tidak' ) return ; end

  delete(handles.figure1); awal

3. Form BWT

  function varargout = bwt(varargin) function bwt_OpeningFcn(hObject, eventdata, handles, varargin)

  handles.output = hObject; guidata(hObject, handles); A = imread( 'Awal.jpg' ); axes(handles.axes_asli); imshow(A); axes(handles.axes_hasil); imshow(A); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' );

  

function varargout = bwt_OutputFcn(hObject, eventdata, handles)

  varargout{1} = handles.output;

  function btn_buka_Callback(hObject, eventdata, handles) global input_citra; global img;

  set(handles.text_proses, 'String' , 'Wait...' ); pause(0.1); [filename, pathname] = uigetfile({ '*.bmp' }, 'Buka File Citra' );

  if ~isequal (filename,0) && ~isequal (pathname,0)

  [pathstr,name,ext] = fileparts([pathname filename]);

  if ext == '.bmp'

  input_citra = fullfile(pathname,filename); info = imfinfo(fullfile(pathname,filename)); size_file = info.FileSize/1000; str = num2str(size_file, '%1.1f Kb' ); img = imread(input_citra); axes(handles.axes_asli); imshow(img); A = imread( 'Awal.jpg' ); axes(handles.axes_hasil); imshow(A); dim3 = size(img,3);

  if (dim3 > 1)

  lihat_citra

  end

  edit_hasil = ' ' ; edit_ukuran = 'Ukuran File Citra' ; set(handles.edit_citra_hasil, 'String' ,edit_hasil); set(handles.size2, 'String' ,edit_ukuran); set(handles.edit1, 'String' ,edit_hasil); set(handles.edit2, 'String' ,edit_hasil); set(handles.edit3, 'String' ,edit_hasil); set(handles.edit_citra_asli, 'String' ,filename); set(handles.size1, 'String' ,str); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1);

  else

  errordlg( 'Sistem hanya membaca citra dengan format bitmap

  (*.bmp)' );

  set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1);

  return ; end else

  set(handles.text_proses, 'String' , 'Ready' ); pause(0.1);

  end function btn_kompresi_Callback(hObject, eventdata, handles) global input_citra;

  runtime = cputime; set(handles.text_proses, 'String' , 'Wait...' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1); image = imread(input_citra); assignin( 'base' , 'citraAsli' ,image) [img_kompres] = bwtcomp(image); runtime = cputime - runtime; [ratio] = imratio1(image,img_kompres); set(handles.edit2, 'String' ,ratio); str = num2str(runtime, '%1.2f s' ); set(handles.edit3, 'String' ,str); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'On' ); pause(0.1);

  function btn_dekompresi_Callback(hObject, eventdata, handles)

  runtime = cputime; set(handles.text_proses, 'String' , 'Wait...' ); set(handles.btn_kompresi, 'Enable' , 'Off' ); set(handles.btn_dekompresi, 'Enable' , 'Off' ); pause(0.1); [image_reconst] = ibwtcomp; runtime = cputime - runtime; assignin( 'base' , 'citraHasil' ,image_reconst) str = num2str(runtime, '%1.2f s' ); set(handles.edit1, 'String' ,str); axes(handles.axes_hasil); imshow(image_reconst); file = 'C:\Users\Yudha\Documents\MATLAB\Skripsi\bwt\img

  dekompres\citraDekompres.bmp' ;

  S = getimage(handles.axes_hasil); imwrite(S, file); info = imfinfo(file); size_file_hasil = info.FileSize/1000; str1 = num2str(size_file_hasil, '%1.1f Kb' ); set(handles.edit_citra_hasil, 'String' , 'citraDekompres.bmp' ); set(handles.size2, 'String' ,str1); set(handles.text_proses, 'String' , 'Ready' ); set(handles.btn_kompresi, 'Enable' , 'On' ); set(handles.btn_dekompresi, 'Enable' , 'On' ); pause(0.1);

  function btn_keluar_Callback(hObject, eventdata, handles) selection = questdlg( 'Kembali ke menu awal?' , ...

  'Konfirmasi' , 'Ya' , 'Tidak' , 'Ya' ); if strcmp(selection, 'Tidak' ) return ; end

  delete(handles.figure1); awal

  4. Form Bantuan function varargout = bantuan(varargin) function bantuan_OpeningFcn(hObject, eventdata, handles, varargin)

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

  function varargout = bantuan_OutputFcn(hObject, eventdata,

  handles) varargout{1} = handles.output;

  function btn_keluar_Callback(hObject, eventdata, handles)

  delete(handles.figure1); awal

  5. Form Profil Programmer function varargout = programmer(varargin)

function programmer_OpeningFcn(h, eventdata, handles, varargin)

  handles.output = h; guidata(h, handles); axes(handles.axes1); img = imread( 'yudha.jpg' ); image(img); grid off ; axis off ;

  function varargout = programmer_OutputFcn(hObject, eventdata,

  handles) varargout{1} = handles.output;

  function btn_keluar_Callback(hObject, eventdata, handles)

  delete(handles.figure1); awal

  6. Function imratio function ratio = imratio(f1,f2)

  narginchk(2, 2); ratio = bytes(f1) / bytes(f2);

  function b = bytes(f) if isstruct(f)

  info = dir( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\jpeg\file

  kompres\kompresJPEG.mat' );

  b = info.bytes;

  else

  info = whos( 'f' ); b = info.bytes;

  end

  7. Function imratio1 function ratio = imratio1(f1,f2)

  narginchk(2, 2); ratio = bytes(f1) / bytes(f2);

  function b = bytes(f) if isstruct(f)

  info = dir( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\bwt\file

  kompres\kompresBWT.mat' );

  b = info.bytes;

  else

  info = whos( 'f' ); b = info.bytes;

  end

  8. Form lihat_citra function varargout = lihat_citra(varargin) function lihat_citra_OpeningFcn(hObject, eventdata, handles,

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

  global img;

  R = img(:,:,1); axes(handles.axes1); imshow(R); G = img(:,:,2); axes(handles.axes2); imshow(G); B = img(:,:,3); axes(handles.axes3); imshow(B); img1 = rgb2ycbcr(img); y = img1(:,:,1); axes(handles.axes4); imshow(y); cb = img1(:,:,2); axes(handles.axes5); imshow(cb); cr = img1(:,:,3); axes(handles.axes6); imshow(cr);

  

function varargout = lihat_citra_OutputFcn(hObject, eventdata,

  handles) varargout{1} = handles.output;

  function pushbutton1_Callback(hObject, eventdata, handles)

  delete(handles.figure1);

9. Function im2jpeg

  function y = im2jpeg(image, quality)

  img = image; [Height,Width,Depth] = size(img); img1 = img(1:Height,1:Width,:); clear img ; img = img1;

  if Depth > 1

  img = rgb2ycbcr(img); y = img(:,:,1); cb = img(:,:,2); cr = img(:,:,3); x = uint8(y);

  else

  x = uint8(img); cb = char; cr = char;

  end

  m = [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] * quality; order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ... 41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ... 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ... 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ... 62 63 56 64]; [xm, xn] = size(x); x = double(x) - 128; t = dctmtx(8); y = blkproc(x, [8 8], 'P1 * x * P2' , t, t'); y = blkproc(y, [8 8], 'round(x ./ P1)' , m); y = im2col(y, [8 8], 'distinct' ); xb = size(y, 2); y = y(order, :); eob = max(y(:)) + 1; r = zeros(numel(y) + size(y, 2), 1); count = 0;

  for j = 1:xb

  i = max(find(y(:, j)));

  if isempty(i)

  i = 0;

  end

  p = count + 1; q = p + i; r(p:q) = [y(1:i, j); eob]; count = count + i + 1;

  end

  r((count + 1):end) = []; y = struct; y.size = uint16([xm xn]); y.numblocks = uint16(xb); y.quality = uint16(quality * 100); y.huffman = mat2huff(r); y.chromaBlue = cb; y.chromaRed = cr;

  %save compressed file

  save ( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\jpeg\file

  kompres\kompresJPEG.mat' , 'y' ); end

10. Function mat2huff

  function y = mat2huff(x)

if ~ismatrix(x) || ~isreal(x) || (~isnumeric(x) && ~islogical(x))

  error( 'X must be a 2-D real numeric or logical matrix.' );

  end % Store the size of input x.

  y.size = uint32(size(x));

  

% Find the range of x values and store its minimum value biased

% by +32768 as a UINT16.

  x = round(double(x)); xmin = min(x(:)); xmax = max(x(:)); pmin = double(int16(xmin)); pmin = uint16(pmin + 32768); y.min = pmin;

  % Compute the input histogram between xmin and xmax with unit % width bins, scale to UINT16, and store. x = x(:)'; h = histc(x, xmin:xmax);

  if max(h) > 65535

  h = 65535 * h / max(h);

  end

  h = uint16(h); y.hist = h; % Code the input matrix and store the result. map = huffman(double(h)); % Make Huffman code map hx = map(x(:) - xmin + 1); % Map image hx = char(hx)'; % Convert to char array hx = hx(:)'; hx(hx == ' ' ) = []; % Remove blanks ysize = ceil(length(hx) / 16); % Compute encoded size hx16 = repmat( '0' , 1, ysize * 16); % Pre-allocate modulo-16 vector hx16(1:length(hx)) = hx; % Make hx modulo-16 in length hx16 = reshape(hx16, 16, ysize); % Reshape to 16-character words hx16 = hx16' - '0' ; % Convert binary string to decimal twos = pow2(15:-1:0); y.code = uint16(sum(hx16 .* twos(ones(ysize, 1), :), 2))';

  end

11. Function huff2mat

  function x = huff2mat(y)

if ~isstruct(y) || ~isfield(y, 'min' ) || ~isfield(y, 'size' ) ||

...

  ~isfield(y, 'hist' ) || ~isfield(y, 'code' ) error( 'The input must be a structure as returned by

MAT2HUFF.' );

  end

  sz = double(y.size); m = sz(1); n = sz(2); xmin = double(y.min) - 32768; % Get X minimum map = huffman(double(y.hist)); % Get Huffman code (cell)

% Create a binary search table for the Huffman decoding process.

  

% 'code' contains source symbol strings corresponding to 'link'

% nodes, while 'link' contains the addresses (+) to node pairs for % node symbol strings plus '0' and '1' or addresses (-) to decoded % Huffman codewords in 'map'. Array 'left' is a list of nodes yet to % be processed for 'link' entries.

  code = cellstr(char( '' , '0' , '1' )); % Set starting conditions as link = [2; 0; 0]; left = [2 3]; % 3 nodes w/2 unprocessed found = 0; tofind = length(map); % Tracking variables

  while ~isempty(left) && (found < tofind)

  look = find(strcmp(map, code{left(1)})); % Is string in map?

  if look % Yes

  link(left(1)) = -look; % Point to Huffman map left = left(2:end); % Delete current node found = found + 1; % Increment codes found

  else % No, add 2 nodes & pointers

  len = length(code); % Put pointers in node link(left(1)) = len + 1; link = [link; 0; 0]; % Add unprocessed nodes code{end + 1} = strcat(code{left(1)}, '0' ); code{end + 1} = strcat(code{left(1)}, '1' ); left = left(2:end); % Remove processed node left = [left len + 1 len + 2]; % Add 2 unprocessed nodes

  end end

  x = unravel(y.code', link, m * n); % Decode using C 'unravel' x = x + xmin - 1; % X minimum offset adjust x = reshape(x, m, n); % Make vector an array

  end

12. Function jpeg2im

  function output = jpeg2im

  load ( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\jpeg\file

  kompres\kompresJPEG.mat' );

  m = [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]; order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ... 41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ... 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ... 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ... 62 63 56 64]; rev = order;

  for k = 1:length(order)

  rev(k) = find(order == k);

  end

  m = double(y.quality) / 100 * m; xb = double(y.numblocks); sz = double(y.size); xn = sz(2); xm = sz(1); x = huff2mat(y.huffman); eob = max(x(:)); z = zeros(64, xb); k = 1;

  for j = 1:xb for i = 1:64 if x(k) == eob

  k = k + 1; break ;

  else

  z(i, j) = x(k); k = k + 1;

  end end end

  z = z(rev, :); x = col2im(z, [8 8], [xm xn], 'distinct' ); x = blkproc(x, [8 8], 'x .* P1' , m); t = dctmtx(8); x = blkproc(x, [8 8], 'P1 * x * P2' , t', t); x = uint8(x + 128); cb = y.chromaBlue; cr = y.chromaRed;

  if ~ischar(cb) && ~ischar(cr)

  RGB(:,:,1) = x; RGB(:,:,2) = uint8(cb); RGB(:,:,3) = uint8(cr); img = ycbcr2rgb(RGB); output = im2uint8(img);

  else

  output = im2uint8(x);

  end end

13. Function huffman

  function CODE = huffman(p)

  narginchk(1, 1);

  if (~ismatrix(p)) || (min(size(p)) > 1) || ~isreal(p) ||

  ~isnumeric(p) error( 'P must be a real numeric vector.' );

  end

% Global variable surviving all recursions of function 'makecode'

global CODE

  CODE = cell(length(p), 1); % Init the global cell array if length(p) > 1 % When more than one symbol ... p = p / sum(p); % Normalize the input probabilities s = reduce(p); % Do Huffman source symbol reductions makecode(s, []); % Recursively generate the code

  else

  CODE = { '1' }; % Else, trivial one symbol case!

  end ; for i = 1:numel(CODE)

  c = CODE{i}; t = c; c(c== '1' ) = '0' ; c(t== '0' ) = '1' ; CODE{i} = c;

  end end function s = reduce(p) % Create a Huffman source reduction tree in a MATLAB cell structure

% by performing source symbol reductions until there are only two % reduced symbols remaining s = cell(length(p), 1);

  % Generate a starting tree with symbol nodes 1, 2, 3, ... to % reference the symbol probabilities. for i = 1:length(p)

  s{i} = i;

  end while numel(s) > 2

  [p, i] = sort(p); % Sort the symbol probabilities p(2) = p(1) + p(2); % Merge the 2 lowest probabilities p(1) = []; % and prune the lowest one s = s(i); % Reorder tree for new probabilities s{2} = {s{1}, s{2}}; % and merge & prune its nodes s(1) = []; % to match the probabilities

  end end function makecode(sc, codeword) % Scan the nodes of a Huffman source reduction tree recursively to % generate the indicated variable length code words. % Global variable surviving all recursive calls global CODE if isa(sc, 'cell' ) % For cell array nodes,

  makecode(sc{1}, [codeword 0]); % add a 0 if the 1st element makecode(sc{2}, [codeword 1]); % or a 1 if the 2nd

  else % For leaf (numeric) nodes,

  CODE{sc} = char( '0' + codeword); % create a char code string

  end end

14. Function ”unravel”

  #include "mex.h" //unravel = decodes a variable-length bit stream //use mex to connect between c and matlab m-file

void unravel( unsigned short *hx, double *link, double *x, double

  xsz, int hxsz) {

  int i = 15, j = 0, k = 0, n = 0; while (xsz - k) { if (*(link + n) > 0) { if ((*(hx + j) >> i) & 0x0001)

  n = *(link + n);

  else n = *(link + n) - 1; if (i) i--; else {j++; i = 15;} if (j > hxsz)

  mexErrMsgTxt( "Out of code bits ???" ); }

  else {

  • (x + k++) = -*(link + n); n = 0; } }

  if (k == xsz - 1)

  • (x + k++) = -*(link + n); }

  void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const

  mxArray *prhs[]) {

  double *link, *x, xsz; unsigned short *hx; int hxsz; if (nrhs != 3)

  mexErrMsgTxt( "Threeinputs required." );

  else if (nlhs > 1)

  mexErrMsgTxt( "Too many output arguments." );

  if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) ||

  mxGetN(prhs[2]) * mxGetM(prhs[2]) != 1) mexErrMsgTxt( "Input XSIZE must be a scalar." ); hx = mxGetPr(prhs[0]); link = mxGetPr(prhs[1]); xsz = mxGetScalar(prhs[2]); hxsz = mxGetM(prhs[0]); plhs[0] = mxCreateDoubleMatrix(xsz, 1, mxREAL); x = mxGetPr(plhs[0]); unravel(hx,link, x, xsz, hxsz); }

15. Function bwtcomp

  function f = bwtcomp(image)

  img = image; [Height,Width,Depth] = size(img); img1 = img(1:Height,1:Width,:); clear img ; img = img1;

  if Depth > 1

  img = rgb2ycbcr(img); y = img(:,:,1); cb = img(:,:,2); cr = img(:,:,3); x = uint8(y);

  else

  x = uint8(img); cb = char; cr = char;

  end order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ...

  41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ... 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ... 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ...

  62 63 56 64]; [xm, xn] = size(x); x = double(x); y = im2col(x, [8 8], 'distinct' ); xb = size(y, 2); y = y(order, :); y = y(:)'; bagi = xb/4;

  for i=1:bagi

  r{i} = y(floor((end/bagi)*(i-1)+1):ceil((end/bagi)*i)); code{i} = bwtenc(r{i});

  end

  f = struct; f.size = uint16([xm xn]); f.numblocks = uint16(xb); f.bwt = code; f.chromaBlue = cb; f.chromaRed = cr;

  %save compressed file

  save ( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\bwt\file

  kompres\kompresBWT.mat' , 'f' ); end

16. Function bwtenc

  function out_data = bwtenc(input)

  input = input(:)'; R = zeros(1,2*length(input));

  for length_sort=1:length(R) if (length_sort>length(input))

  R(length_sort) = input(length_sort-length(input));

  else

  R(length_sort) = input(length_sort);

  end end

  table_sort = zeros(length(input),length(input));

  for row_sort=1:length(input)

  table_sort(row_sort,:) = R(row_sort:length(input)+row_sort-1);

  end

  [lexi_data,ind] = sortrows(table_sort); encoded_data = lexi_data(:,length(input)); index = find(ind==2,1); out_data = [encoded_data',index];

  end

  17. Function bwtdec function decoded_data = bwtdec(input)

  encoded_data = input(1:length(input)-1); index = input(length(input)); sorted_data = sort(encoded_data); R = ones(1,length(encoded_data))'; vector = zeros(1,length(encoded_data))';

  %preparing vector table for i=1:length(sorted_data) for j=1:length(sorted_data) if (encoded_data(j) == sorted_data(i) && R(j))

  R(j); vector(i) = j; R(j) = 0;

  break end end end

  decoded_data = zeros(1,length(encoded_data));

  %getting original data back for i = 1:length(encoded_data)

  decoded_data(i)= encoded_data(index); index = vector(index);

  end end

  18. Function ibwtcomp function output = ibwtcomp

  load ( 'C:\Users\Yudha\Documents\MATLAB\Skripsi\bwt\file

  kompres\kompresBWT.mat' );

  bagi = f.numblocks/4;

  for m=1:bagi

  i{m} = bwtdec(f.bwt{m});

  end

  y = cell2mat(i); order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ... 41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ... 43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ... 45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ... 62 63 56 64]; rev = order;

  for k = 1:length(order)

  rev(k) = find(order == k);

  end

  xb = double(f.numblocks); sz = double(f.size); xn = sz(2); xm = sz(1); y = reshape(y,64,xb); y = y(rev, :); x = col2im(y, [8 8], [xm xn], 'distinct' ); x = uint8(x); cb = f.chromaBlue; cr = f.chromaRed;

  if ~ischar(cb) && ~ischar(cr)

  RGB(:,:,1) = x; RGB(:,:,2) = uint8(cb); RGB(:,:,3) = uint8(cr); img = ycbcr2rgb(RGB); output = im2uint8(img);

  else

  output = im2uint8(x);

  end end

19. License.m

  %------------------------------LICENSE---------------------------- %Program ini dibuat dengan hak cipta %yang bertujuan untuk menghindari plagiat %dan dituliskan dalam daftar pustaka sebagai rujukan.

  %Dibuat oleh diri sendiri dengan bantuan buku dan internet: %awal.fig, jpeg.fig, bwt.fig, bantuan.fig, programmer.fig, lihat_citra.fig,

%awal.m, jpeg.m, bwt.m, bantuan.m, programmer.m, lihat_citra.m,

imratio.m, %imratio1.m, bwtcomp.m, ibwtcomp.m %Dibuat oleh Gonzales, Woods, dan Eddins dengan revisi:

%im2jpeg.m, jpeg2im.m, huff2mat.m, mat2huff, huffman.m, unravel.c

%Dibuat oleh Akhtar dan diambil dari matlab file exchange dengan

revisi: %bwtenc.m, bwtdec.m.

  B-1

CURRICULUM VITAE

  Data Pribadi Nama : Yudha Prayogie S Tempat/Tanggal Lahir : Binjai / 25 November 1992 Agama : Islam Kewarganegaraan : Indonesia Alamat Sekarang : Jl. Pendidikan No.1 Lk. V Binjai Utara Kota Binjai Alamat Orang Tua : Jl. Pendidikan No.1 Lk. V Binjai Utara Kota Binjai Telp/ HP : 0857 6007 4004 Email : yudhaprayogie@gmail.com Riwayat Pendidikan [1998 : SD Swasta Ahmad Yani Binjai

  • – 2004] [2004 : SMP Swasta Ahmad Yani Binjai – 2007] [2007 : SMA Negeri 1 Binjai – 2010] [2010 – 2015] : S1 Ilmu Komputer Universitas Sumatera Utara

  Keahlian Keahlian Komputer : Pemrograman : Pascal, C++, Matlab. Database : MySQL Perkantoran : Microsoft Office

  Universitas Sumatera Utara

  B-2 Pengalaman Organisasi [2007 : Bengkel Sastra Bianglala SMA Negeri 1 Binjai

  • – 2009] [2008 : OSIS SMA Negeri 1 Binjai – 2009] [2011 – 2013] : Anggota Ilmu Komputer Laboratory Center (IKLC) [2012 : Anggota Wawasan Kontemporer (Waskom) IMILKOM
  • – 2013]

  Pengalaman Kepanitiaan [2012] : Ketua Acara PORSENI IMILKOM 2012 [2012] : Anggota Acara PMB IMILKOM 2012 [2013] : Anggota Acara ARTechno 2013 [2014] : Anggota Acara Seminar Open BTS 2014 Seminar [2011] : Seminar Nasional Bidang Komputer 2011 Universitas Sumatera Utara

  Universitas Sumatera Utara