-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubband_coding.m
65 lines (43 loc) · 1.42 KB
/
Subband_coding.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
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
65
clear, clc, close all;
% Read the grayscale image
image = imread('q3.png');
if length(size(image)) == 3
image = rgb2gray(image);
end
% Define the filter coefficients of 4-tap daubechies filter
H0 =[0.03489, -0.010983, -0.06286, 0.223907, 0.55686,...
0.357976, -0.0239002, -0.0759409];
H1 = [-0.0759409, 0.0239002, 0.357976, -0.55686, -0.223907,...
0.06286, 0.010983, -0.03489];
low_filtered_image = image;
high_filtered_image = image;
num_stages = 4;
flag = 1;
for i = 1 : num_stages
low_filtered_image = floor(conv2(low_filtered_image, H0, 'same'));
% high_filtered_image = floor(conv2(low_filtered_image, H1, 'same'));
high_filtered_image = round(filter(H1, 1, high_filtered_image));
if flag == 1
low_filtered_image =downsample(low_filtered_image.', 2).';
high_filtered_image =downsample(high_filtered_image.', 2).';
flag = 0;
else
low_filtered_image =downsample(low_filtered_image, 2);
high_filtered_image =downsample(high_filtered_image, 2);
flag = 1;
end
% figure();
end
% low_freq_image = uint8(low_filtered_image);
% high_freq_image = uint8(high_filtered_image);
% Display the original and filtered images
figure;
subplot(3, 1, 1);
imgsc(image);
title('Original Image');
subplot(3, 1, 2);
imgsc(low_freq_image);
title('compressed image low freq');
subplot(3, 1, 3);
imgsc(high_freq_image);
title('compressed image high freq');