-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotwavelet2.m
81 lines (68 loc) · 2.28 KB
/
plotwavelet2.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function plotwavelet2(C,S,level,wavelet,rv,mode)
% Plot wavelet image (2D) decomposition.
% A short and simple function for displaying wavelet image decomposition
% coefficients in 'tree' or 'square' mode
%
% Required : MATLAB, Image Processing Toolbox, Wavelet Toolbox
%
% plotwavelet2(C,S,level,wavelet,rv,mode)
%
% Input: C : wavelet coefficients (see wavedec2)
% S : corresponding bookkeeping matrix (see wavedec2)
% level : level decomposition
% wavelet : name of the wavelet
% rv : rescale value, typically the length of the colormap
% (see "Wavelets: Working with Images" documentation)
% mode : 'tree' or 'square'
%
% Output: none
%
% Example:
%
% % Load image
% load wbarb;
% % Define wavelet of your choice
% wavelet = 'haar';
% % Define wavelet decomposition level
% level = 2;
% % Compute multilevel 2D wavelet decomposition
% [C S] = wavedec2(X,level,wavelet);
% % Define colormap and set rescale value
% colormap(map); rv = length(map);
% % Plot wavelet decomposition using square mode
% plotwavelet2(C,S,level,wavelet,rv,'square');
% title(['Decomposition at level ',num2str(level)]);
%
%
% Benjamin Tremoulheac, benjamin.tremoulheac@univ-tlse3.fr, Apr 2010
A = cell(1,level); H = A; V = A; D = A;
for k = 1:level
A{k} = appcoef2(C,S,wavelet,k); % approx
[H{k} V{k} D{k}] = detcoef2('a',C,S,k); % details
A{k} = wcodemat(A{k},rv);
H{k} = wcodemat(H{k},rv);
V{k} = wcodemat(V{k},rv);
D{k} = wcodemat(D{k},rv);
end
if strcmp(mode,'tree')
aff = 0;
for k = 1:level
subplot(level,4,aff+1); image(A{k});
title(['Approximation A',num2str(k)]);
subplot(level,4,aff+2); image(H{k});
title(['Horizontal Detail ',num2str(k)]);
subplot(level,4,aff+3); image(V{k});
title(['Vertical Detail ',num2str(k)]);
subplot(level,4,aff+4); image(D{k});
title(['Diagonal Detail ',num2str(k)]);
aff = aff + 4;
end
elseif strcmp(mode,'square')
dec = cell(1,level);
dec{level} = [A{level} H{level} ; V{level} D{level}];
for k = level-1:-1:1
dec{k} = [imresize(dec{k+1},size(H{k})) H{k} ; V{k} D{k}];
end
image(dec{1});
end
end