📄 nmdemo.m
字号:
function nmdemo(Num)
%NMDEMO Nonlinear multiresolution demos.
%
% Type "nmdemo" and press enter to run.
%
% Pascal Getreuer 2005-2006
global G_DEMO
if nargin == 0
if ~isempty(G_DEMO)
figure(G_DEMO(1));
return;
end
% Create main demo window
G_DEMO(1) = figure('Name','WaveDemo','Numbertitle','off','Menubar','none',...
'Resize','off','CloseRequestFcn',['global G_DEMO,if ishandle(G_DEMO(5)),',...
'close(G_DEMO(5));end,clear global G_DEMO;closereq;'],'NextPlot','new');
set(G_DEMO(1),'Position',[40,95,210,185]);
G_DEMO(2) = uicontrol('Style','list','Position',[10,40,190,140],'String',{'1 S-Transform',...
'2 Morphological Haar Wavelet','3 Linear Binary Wavelet',...
'4 Morphological Binary Wavelet','5 Max-Lifting Wavelet',...
'6 Denoising with Max-Lifting','7 ENO Interpolation',...
'8 ENO Multiresolution','9 ENO Approximation',' References'});
G_DEMO(3) = uicontrol('Style','pushbutton','String','Select','Position',[35,8,65,25],...
'Callback',['global G_DEMO;',mfilename,'(get(G_DEMO(2),''Value''));']);
G_DEMO(4) = uicontrol('Style','pushbutton','String','Close','Position',[114,8,65,25],...
'Callback','close;');
set(G_DEMO(3:4),'BackgroundColor',get(G_DEMO(1),'Color'));
G_DEMO(5) = nan;
elseif ~isempty(G_DEMO)
if ~ishandle(G_DEMO(5))
G_DEMO(5) = figure('Name','','Numbertitle','off'); % Create a figure window
else
figure(G_DEMO(5)); % Reuse same figure window if possible
clf;
end
switch Num
case 1 %%% Demo 1: S-Transform %%%
fprintf(['\n S-Transform\n\n',...
'The sequential transform or "S-transform" is a nonlinear modification to\n',...
'the Haar wavelet such that an integer-valued signal has integer-value\n'...
'transform coefficients. The decomposition is\n\n',...
' s[n] = floor( (x[2n] + x[2n+1])/2 )\n d[n] = x[2n+1] - x[2n]\n\n',...
'and reconstruction is\n\n x[2n] = s[n] - floor(d[n]/2)\n',...
' x[2n+1] = s[n] + floor( (d[n] + 1)/2 )\n\n',...
'The figure shows an example decomposition. This transform is implemented\n',...
'in SEQHAAR and SEQHAAR2.\n\n\n']);
set(G_DEMO(5),'Name','S-Transform');
x = [1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,...
0,0,3,3,3,3,3,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3];
subplot(2,1,1);
plot(0:63,x,'.-');
xlim([0,63]);
title('Original');
subplot(2,1,2);
y = seqhaar(x,2); % Apply the S-transform with two stages of decomposition
plot(0:15,y(1:16),'b.-',16:63,y(17:64),'b.',...
[15.5,15.5],[-4,4],'k',[31.5,31.5],[-4,4],'k');
axis([0,63,-4,4]);
title('Two levels of decomposition');
case 2 %%% Demo 2: Morphological Haar Wavelet %%%
fprintf(['\n Morphological Haar Wavelet\n\n',...
'Like the S-transform (see previous demo), the morphological Haar wavelet\n',...
'is a nonlinear modification of the Haar wavelet such that applying the\n',...
'transform to an integer-valued signal results in an integer-valued output.\n',...
'The morphological Haar wavelet uses erosion instead of averaging for its\n',...
'decimation operator. Consequently, jumps are represented more crisply than\n',...
'with the S-transform. The morphological Haar wavelet decomposition is\n\n',...
' s[n] = min {x[2n], x[2n+1]}\n d[n] = x[2n] - x[2n+1]\n\n',...
'and reconstruction is\n\n x[2n] = s[n] + max {d[n], 0}\n',...
' x[2n+1] = s[n] - min {d[n], 0}\n\n',...
'The figure shows an example decomposition. This transform is implemented\n',...
'in MHAAR.\n\n\n']);
set(G_DEMO(5),'Name','Morphological Haar Wavelet');
x = [1,1,1,1,1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,...
0,0,3,3,3,3,3,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3];
subplot(2,1,1);
plot(0:63,x,'.-');
xlim([0,63]);
title('Original');
subplot(2,1,2);
y = mhaar(x,2);
plot(0:15,y(1:16),'b.-',16:63,y(17:64),'b.',...
[15.5,15.5],[-4,4],'k',[31.5,31.5],[-4,4],'k');
axis([0,63,-4,4]);
title('Two levels of decomposition');
case 3 %%% Demo 3: Linear Binary Wavelet %%%
fprintf(['\n Linear Binary Wavelet\n\n',...
'A binary wavelet transform converts a binary image to a multiresolution\n',...
'representation where all transform coefficients are 0 or 1. One such\n',...
'transform is demonstrated here. The decomposition is\n\n',...
' s[n] = x[2n] + x[2n-1] + x[2n-2]\n',...
' d[n] = x[2n] + x[2n-1]\n\n',...
'and retain only the lowest bit in s[n] and d[n], (e.g. \n',...
's[n] = mod(s[n],2) ). Reconstruction is\n\n',...
' s2[2n] = s[n], s2[2n+1] = 0\n',...
' d2[2n] = d[n], d2[2n+1] = 0\n',...
' x[n] = s2[n] + s2[n-1] + d2[n] + d2[n-1] + d2[n-2]\n\n',...
'Again, retain only the lowest bit in x(n). The figure shows an example\n',...
'decomposition. Note the "binary blurring" in the upper-left corner\n',...
'(LLL subband). This transform is implemented in LINBWT and LINBWT2.\n\n\n']);
set(G_DEMO(5),'Name','Linear Binary Wavelet');
[x,y] = meshgrid(1:128,1:128);
x = ((abs(x-64).^.7+abs(y-64).^.7) < 17);
subplot(1,2,1);
imagesc(x); % Display original image
colormap([0,0,0;1,1,1]);
axis image;
title('Original');
subplot(1,2,2);
imagesc(linbwt2(x,2)); % Display decomposition
line([64.5,64.5],[1,128]);
line([1,128],[64.5,64.5]);
line([32.5,32.5],[1,64.5]);
line([1,64.5],[32.5,32.5]);
colormap([0,0,0;1,1,1]);
axis image;
title('Two levels of decomposition');
case 4 %%% Demo 4: Morphological Binary Wavelet %%%
fprintf(['\n Morphological Binary Wavelet\n\n',...
'Another binary wavelet transform is the 2D median morphological wavelet.\n',...
'The transform uses a 5-element median in the decimation operator. Its\n',...
'implementation is computationally cheap with only median operations and\n',...
'XOR operations. The decomposition is\n\n',...
' s[n,m] = median {x[2n,2m], x[2n,2m], x[2n+1,2m], ...\n',...
' x[2n,2m+1], x[2n+1,2m+1]}\n',...
' dv[n,m] = x[2n,2m] XOR x[2n,2m+1]\n dh[n,m] = x[2n,2m] XOR x[2n+1,2m]\n',...
' dd[n,m] = x[2n,2m] XOR x[2n+1,2m+1]\n\n',...
'and reconstruction is\n\n',...
' x[2n,2m] = s[n,m] XOR min {dv[n,m], dh[n,m], dd[n,m]}\n',...
' x[2n+1,2m] = x[2n,2m] XOR dh[n,m]\n x[2n,2m+1] = x[2n,2m] XOR dv[n,m]\n',...
' x[2n+1,2m+1] = x[2n,2m] XOR dd[n,m]\n\n',...
'The figure shows an example decomposition. This binary wavelet preserves\n',...
'edges more crisply than the transform in the previous demo; it does not\n',...
'have "binary blurring". This transform is implemented in MORPHBWT2.\n\n\n']);
set(G_DEMO(5),'Name','Morphological Binary Wavelet');
[x,y] = meshgrid(1:128,1:128);
x = ((abs(x-64).^.7+abs(y-64).^.7) < 17);
subplot(1,2,1);
imagesc(x); % Display original image
colormap([0,0,0;1,1,1]);
axis image;
title('Original');
subplot(1,2,2);
imagesc(morphbwt2(x,2)); % Display Decomposition
hold on;
line([64.5,64.5],[1,128]);
line([1,128],[64.5,64.5]);
line([32.5,32.5],[1,64.5]);
line([1,64.5],[32.5,32.5]);
colormap([0,0,0;1,1,1]);
axis image;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -