📄 bestpartitiondemo.m
字号:
function BestPartitionDemo(varargin)
%Usage: BestPartitionDemo
%Description: Demo for paper Ridgelet Packets
%Version: 6
%Author: Danzhu Shi and Ana Georgina Flesia
%Date: May 8, 2002
if nargin == 0
fig = figure(1);
fs = 8; %default font size
clf reset;
set(fig,'pos',[104 229 672 504],'Name', 'Ridgelet Packet Analysis in Adaptively Chosen Basis', 'NumberTitle', 'off');
set(fig,'doublebuffer','on','userdata',1);
txt = strvcat('Please choose the parameters :',...
'Names : name of a 2-d image.', ...
'D : [D1,D2] maximum depth of splitting', ...
'Entropy : type of entropy to record in tree, options are', ...
' ''Entropy'' -- Coifman-Wickerhauser', ...
' ''Log'' -- sum log |th_i|', ...
' ''l^p'' -- sum |th_i|^p, 0<p<2, p=par', ...
' ''N(eps)'' -- #>= eps, eps = par', ...
' ''Risk'' -- sum min(th_i^2,eps^2), eps=par', ...
' ''Sum'' -- sum th_i', ...
' ''SURE'' -- SURE(Thresholding), thresh = par', ...
'EntPar : extra parameter, depends on type of entropy.', ...
' ',...
'For example, BestPartitionDemo(''Lenna'',[3,3],''l^p'',1.5)');
uicontrol( ...
'tag', 'Instruction_text', ...
'style', 'text', ...
'units', 'normal', ...
'position', [.25 .4 .8 .5], ...
'string', txt, ...
'HorizontalAlignment', 'left', ...
'backgroundcolor', [.8 .8 .8], ...
'fontsize', fs);
nameRange=['Barton '; 'Canaletto '; 'Coifman '; 'Daubechies '; ...
'Fingerprint'; 'Lincoln '; 'Lenna '; 'MRIScan '; ...
'Phone '];
uicontrol( ...
'tag','Name_text', ...
'style','text', ...
'units','normal', ...
'position', [.1 .32, .18 .06], ...
'string','Names', ...
'backgroundcolor', [0.8 0.8 0.8],...
'fontsize',fs);
uicontrol( ...
'tag','NameRange', ...
'style','list', ...
'units','normal', ...
'position', [.1 .15 .18 .20], ...
'string',{nameRange}, ...
'backgroundcolor',[0.8 0.8 0.8], ...
'fontsize',fs, ...
'callback', 'BestPartitionDemo(''NameRange_Callback'')');
entropyRange=['Entropy'; 'Log '; 'l^p '; 'N(eps) '; ...
'Risk '; 'Sum '; 'SURE '];
uicontrol( ...
'tag','Entropy_text', ...
'style','text', ...
'units','normal', ...
'position', [.3 .32, .12 .06], ...
'string','Entropies', ...
'backgroundcolor', [0.8 0.8 0.8],...
'fontsize',fs);
uicontrol( ...
'tag','EntropyRange', ...
'style','list', ...
'units','normal', ...
'position', [.3 .15 .12 .20], ...
'string',{entropyRange}, ...
'backgroundcolor',[0.8 0.8 0.8], ...
'fontsize',fs, ...
'callback', 'BestPartitionDemo(''EntropyRange_Callback'')');
uicontrol( ...
'tag','D1_text', ...
'style','text', ...
'units','normal', ...
'position', [.5 .32, .08 .06], ...
'string','D1', ...
'backgroundcolor', [0.8 0.8 0.8],...
'fontsize',fs);
uicontrol( ...
'tag','D1Range', ...
'style','list', ...
'units','normal', ...
'position', [.5 .15 .08 .20], ...
'string',{num2str([2:6]')}, ...
'backgroundcolor',[0.8 0.8 0.8], ...
'fontsize',fs, ...
'callback', 'BestPartitionDemo(''D1Range_Callback'')');
uicontrol( ...
'tag','D2_text', ...
'style','text', ...
'units','normal', ...
'position', [.6 .32 .08 .06], ...
'string','D2', ...
'backgroundcolor', [0.8 0.8 0.8],...
'fontsize',fs);
uicontrol( ...
'tag','D2Range', ...
'style','list', ...
'units','normal', ...
'position', [.6 .15 .08 .20], ...
'string',{num2str([2:6]')}, ...
'backgroundcolor',[0.8 0.8 0.8], ...
'fontsize',fs, ...
'callback', 'BestPartitionDemo(''D2Range_Callback'')');
uicontrol( ...
'tag','EntPar_text', ...
'style','text', ...
'units','normal', ...
'position', [.7 .32, .08 .06], ...
'string','EntPar', ...
'backgroundcolor', [0.8 0.8 0.8],...
'fontsize',fs);
uicontrol( ...
'tag','EntParRange', ...
'style','list', ...
'units','normal', ...
'position', [.7 .15 .08 .20], ...
'string',{num2str([1:0.5:3]')}, ...
'HorizontalAlignment', 'left', ...
'backgroundcolor',[0.8 0.8 0.8], ...
'fontsize',fs, ...
'callback', 'BestPartitionDemo(''EntParRange_Callback'')');
uicontrol( ...
'tag', 'draw_pushbutton', ...
'style','pushbutton', ...
'units','normal', ...
'position', [.85 .25 .1 .05], ...
'string','Draw', ...
'fontsize',fs, ...
'callback','BestPartitionDemo(''draw_Callback'')');
uicontrol( ...
'tag', 'close_pushbutton', ...
'style','pushbutton', ...
'units','normal', ...
'position', [.85 .15 .1 .05], ...
'string','Close', ...
'fontsize',fs, ...
'callback','close');
if nargout > 0
varargout{1} = fig;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
% --------------------------------------------------------------------
function name = NameRange_Callback
handles = guihandles(gcf);
NameInd = get(handles.NameRange, 'Value');
NameRan = get(handles.NameRange, 'String');
name = NameRan{NameInd};
for k=1:length(name)
if name(k)==' ',
name = name(1:(k-1));
break;
end
end
% --------------------------------------------------------------------
function Entropy = EntropyRange_Callback
handles = guihandles(gcf);
EntropyInd = get(handles.EntropyRange, 'Value');
EntropyRan = get(handles.EntropyRange, 'String');
Entropy = EntropyRan{EntropyInd};
for k=1:length(Entropy)
if Entropy(k)==' ',
Entropy = Entropy(1:(k-1));
break;
end
end
% --------------------------------------------------------------------
function D1 = D1Range_Callback
handles = guihandles(gcf);
D1Ind = get(handles.D1Range, 'Value');
D1Ran = get(handles.D1Range, 'String');
D1 = str2double(D1Ran(D1Ind));
% --------------------------------------------------------------------
function D2 = D2Range_Callback
handles = guihandles(gcf);
D2Ind = get(handles.D2Range, 'Value');
D2Ran = get(handles.D2Range, 'String');
D2 = str2double(D2Ran(D2Ind));
% --------------------------------------------------------------------
function EntPar = EntParRange_Callback
handles = guihandles(gcf);
EntParInd = get(handles.EntParRange, 'Value');
EntParRan = get(handles.EntParRange, 'String');
EntPar = str2double(EntParRan(EntParInd));
% --------------------------------------------------------------------
function draw_Callback
name = NameRange_Callback;
Entropy = EntropyRange_Callback;
EntPar=EntParRange_Callback;
D1=D1Range_Callback;
D2=D2Range_Callback;
D=[D1, D2];
TestBestPartition(name, D, Entropy, EntPar);
%TestBestPart(name, D, Entropy);
smartset;
%---------------------------------------------------
function TestBestPartition(name,D,Entropy,EntPar)
%
% Ridgelet Packet Analysis in Adaptively Chosen Basis
%
% Inputs
% name name of a 2-d image (loaded from WaveLab); size n by n, n dyadic
% Allowed names are 'Barton', 'Canaletto', 'Coifman', 'Daubechies',...
% 'Fingerprint', 'Lincoln', 'Lenna', 'MRIScan', 'Phone'
% D D = [D1,D2] maximum depth of splitting -- Range D1=2,3,4,5,6; D2=2,3,4,5,6;
% Entropy type of entropy to record in tree: options are
% 'Entropy' -- Coifman-Wickerhauser
% 'Log' -- sum log |th_i|
% 'l^p' -- sum |th_i|^p, 0 < p < 2, p = par
% 'N(eps)' -- #>= eps, eps = par
% 'Risk' -- sum min(th_i^2,eps^2), eps=par
% 'Sum' -- sum th_i
% 'SURE' -- SURE(Thresholding), thresh = par
% EntPar extra parameter, depends on type of entropy$
%
% Description
% Perform an adaptive anisotropic Radial Polar packet analysis on the given image,
% selecting the best anisotropic partitioning basis then plotting the RP coefficients
% for this basis along with the image overlaid by its 2-d polar partition.
%
%Example TestBestPart('Lenna',[3,3],'l^p',1.5)
% check input parameters
if nargin < 3
error('Usage: TestBestPartition(name,D,Entropy[,EntPar])');
end;
if nargin < 4,
EntPar=[];
end
%
if length(D)==1,
D = [ D D];
end
%------------------------------------------
% to supress the output text by ReadImage.m
global WLVERBOSE %set by BeamPath.m
WLVERBOSE = 'No';
%------------------------------------------
im = ReadImage(name);
[s1,s2]=size(im);
if s1~=s2
if min(s1,s2)<=256
im = im(1:min(s1,s2),1:min(s1,s2));
else
im = im(1:256,1:256);
end
end
subplot(1,3,1)
imagesc(im)
axis image;set (gca,'XTick',[]);
set (gca,'YTick',[]);
im = im ./max(im(:));
img0 = im - mean(mean(im));
RPFTGlobal= fft2_rp(img0);
RPFTGlobalShow = RPFTGlobal([2:size(RPFTGlobal,1)/2+1,size(RPFTGlobal,1)/2+1:size(RPFTGlobal,1)],:);
FFTGlobal = fftshift(fft2(im));
FFTGlobalShow = FFTGlobal([2:size(FFTGlobal,1)/2+1,size(FFTGlobal,1)/2+1:size(FFTGlobal,1)],:);
% build a best basis for this image
RPPkt = CalcRPPktTable(RPFTGlobal,D,'Sine');
RPtree = CalcRPStatTree(RPPkt,D,Entropy,EntPar);
bb = BestRPBasis(RPtree,D);
subplot(1,3,2)
AutoImageInv(abs(RPFTGlobalShow));
Polrax = axis; hold on;
PlotRPPartition(bb,'r',Polrax,D);
% calculate statistics
coef = FPT2_RPkt(bb,img0,D);
e = CalcEntropy(coef,Entropy,EntPar);
set(gca,'XTick',[]);
set(gca,'YTick',[]);
% show the fft domain with the best bases
subplot(1,3,3)
AutoImageInv(log(1+abs(FFTGlobalShow)));
Polrax = axis; hold on;
PlotRectoPolarRPPartition(bb,'r',Polrax,D);
set(gca,'XTick',[]);
set(gca,'YTick',[]);
colormap(hot)
%------------------
WLVERBOSE = 'Yes';
%------------------
%---------------------------------------------
function smartset
chd = get(gcf, 'Children');
set(chd(length(chd)), 'Visible', 'off');
set(chd(1), 'Position', [.7 .25 .25 .8], 'FontSize', 7);
set(chd(2), 'Position', [.4 .25 .25 .8], 'FontSize', 7);
set(chd(3), 'Position', [.1 .25 .25 .8], 'FontSize', 7);
%% Part of BeamLab Version:200% Built:Friday,23-Aug-2002 00:00:00% This is Copyrighted Material% For Copying permissions see COPYING.m% Comments? e-mail beamlab@stat.stanford.edu%%% Part of BeamLab Version:200% Built:Saturday,14-Sep-2002 00:00:00% This is Copyrighted Material% For Copying permissions see COPYING.m% Comments? e-mail beamlab@stat.stanford.edu%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -