-
Notifications
You must be signed in to change notification settings - Fork 3
/
LZW_test.m
26 lines (25 loc) · 857 Bytes
/
LZW_test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
% this is a test script for the LZW_img_enc() and LZW_img_dec() functions
% implementing Lempel Ziv Welch method to encode and then decode an image
% calculating the output-to-input compression ratio of the encoding
%
% created by : Ahmed Mohamed Ayman
% date : 13 April 2017
%
%%
% reading the input image
Input = imread('Image.jpg');
%%
% creating binary vector
Binary = imbinarize(Input(:,:,1));
%%
% Encoding the image
Encoded = logical(LZW_img_enc(Binary')); % the transpose to ascend through the elements row by row
%%
% calculating the compression ratio
Ratio = numel(Encoded)/numel(Binary);
%%
% Decoding the encoded image and fitting to the original size
Decoded = logical(vec2mat(LZW_img_dec(Encoded),numel(Binary(1,:))));
%%
% demonstrating the two images before and after encoding
imshowpair(Input,Decoded,'montage');