Repository navigation
Expand file tree
/
Copy pathmainscript.m
More file actions
64 lines (55 loc) · 1.58 KB
/
Copy pathmainscript.m
File metadata and controls
64 lines (55 loc) · 1.58 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
close all; clear all; clc;
dwtmode('per');
% Load images
load galax2.mat %ngc3314
clear map_ngc3314 % map_ngc3314 is just gray colormap.
peppers_gray = imread('peppers_gray.tif'); peppers_gray = double(peppers_gray(:,:,1));
pirate = double(imread('pirate.tif'));
% Parameters
image = pirate;
wname = 'rbio6.8';
decomp_level = 3;
dcpf = 100;
dpz = 100*(1 - 1/dcpf);
useWavelet = 0; % 0 = wavelet packet
% Get information about image
image_size = size(image);
needs_padding = ~all((log2(image_size) - fix(log2(image_size))) == 0);
% Handle padding if necessary
if needs_padding
image_padded = zeros(2.^ceil(log2(image_size)));
image_padded(1:image_size(1),1:image_size(2)) = image;
correct_image = image_padded;
else
correct_image = image;
end
% Do the wavelet
if useWavelet
[C,S] = wavedec2(correct_image, decomp_level, wname);
[C_comp,compressionfactor,percentzeroes,ER,LE] = Compdec(C, S, dpz);
compressed_image = waverec2(C_comp, S, wname);
else
T = wpdec2(correct_image,decomp_level,wname);
[T_comp,compressionfactor,percentzeroes,ER,LE] = Compdwp(T, dpz);
compressed_image = wprec2(T_comp);
end
% De-pad if necessary
if needs_padding
compressed_image = compressed_image(1:image_size(1),1:image_size(2));
end
% Calculate root mean square error
RMS = Rms(compressed_image,image);
% Display images
figure; imshow(image,[]);
figure; imshow(compressed_image,[]);
% Present numbers
disp("Compression factor")
disp(compressionfactor)
disp("Percentage of zeroes")
disp(percentzeroes)
disp("Energy Ratio (%)")
disp(ER)
disp("Loss of information (%)")
disp(LE)
disp("Root square mean error (%)")
disp(RMS*100)