-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.m
128 lines (117 loc) · 3.43 KB
/
demo.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
addpath(genpath('src'))
clear;
rng(1);
load data_demo.mat
%% Piecewise smooth reconstruction with k-th order Mumford-Shah models
% model parameters: gamma, beta
% gamma: complexity parameter(larger gamma -> fewer segments)
% beta: smoothing parameter (larger beta -> stronger smoothing)
sigma = 0.025;
data = pcw_smooth_signal + sigma*randn(size(pcw_smooth_signal));
k = 1;
gamma = 0.03;
beta = 2;
[u_1,changePoints_1] = higherOrderMumShah1D(data,gamma,'order',k,'beta',beta);
k = 2;
gamma = 0.015;
beta = 2;
[u_2,changePoints_2] = higherOrderMumShah1D(data,gamma,'order',k,'beta',beta);
k = 3;
gamma = 0.01;
beta = 2;
[u_3,changePoints_3] = higherOrderMumShah1D(data,gamma,'order',k,'beta',beta);
k = 4;
gamma = 0.01;
beta = 2;
[u_4,changePoints_4] = higherOrderMumShah1D(data,gamma,'order',k,'beta',beta);
% Plot the results
yAxisLim = [0.9*min(data), 1.1*max(data)];
figure('Renderer', 'painters', 'Position', [0 0 1200 600])
subplot(3,2,1)
plotMumShah(pcw_smooth_signal,pcw_smooth_changePoints)
ylim(yAxisLim)
title('Clean piecewise smooth signal')
subplot(3,2,2)
plot(data,'.')
ylim(yAxisLim)
title('Noisy data')
subplot(3,2,3)
plotMumShah(u_1,changePoints_1)
ylim(yAxisLim)
title(['First order Mumford-Shah model'])
subplot(3,2,4)
plotMumShah(u_2,changePoints_2)
ylim(yAxisLim)
title(['Second order Mumford-Shah model'])
subplot(3,2,5)
plotMumShah(u_3,changePoints_3)
ylim(yAxisLim)
title(['Third order Mumford-Shah model'])
subplot(3,2,6)
plotMumShah(u_4,changePoints_4)
ylim(yAxisLim)
title(['Fourth order Mumford-Shah model'])
%% Piecewise polynomial models (k-th order Potts models)
% "Blocks" signal and piecewise constant model (k=1,beta=inf)
sigma = 0.1;
data = blocks_signal + sigma*randn(size(blocks_signal));
k = 1;
gamma = 0.1;
[u,changePoints] = higherOrderMumShah1D(data,gamma,'order',k,'beta',inf);
% Plot the result
yAxisLim = [0.9*min(data), 1.1*max(data)];
figure('Renderer', 'painters', 'Position', [0 0 1200 600])
subplot(1,3,1)
plotMumShah(blocks_signal,blocks_changePoints)
title('Clean "blocks" signal')
ylim(yAxisLim)
subplot(1,3,2)
plot(data,'.')
title('Noisy data')
ylim(yAxisLim)
subplot(1,3,3)
plotMumShah(u,changePoints)
title('Pcw. constant (Potts) reconstruction')
ylim(yAxisLim)
% "Slopes" signal and piecewise affine-linear model (k=2,beta=inf)
sigma = 0.1;
data = slopes_signal + sigma*randn(size(slopes_signal));
k = 2;
gamma = 0.1;
[u,changePoints] = higherOrderMumShah1D(data,gamma,'order',k,'beta',inf);
% Plot the result
yAxisLim = [0.9*min(data), 1.1*max(data)];
figure('Renderer', 'painters', 'Position', [0 0 1200 600])
subplot(1,3,1)
plotMumShah(slopes_signal,slopes_changePoints)
title('Clean "slopes" signal')
ylim(yAxisLim)
subplot(1,3,2)
plot(data,'.')
title('Noisy data')
ylim(yAxisLim)
subplot(1,3,3)
plotMumShah(u,changePoints)
title('Pcw. affine-linear reconstruction')
ylim(yAxisLim)
% "Parabolas" signal and piecewise quadratic model (k=3,beta=inf)
sigma = 0.1;
data = parabolas_signal + sigma*randn(size(parabolas_signal));
k = 3;
gamma = 0.5;
[u,changePoints] = higherOrderMumShah1D(data,gamma,'order',k,'beta',inf);
% Plot the result
yAxisLim = [0.9*min(data), 1.1*max(data)];
figure('Renderer', 'painters', 'Position', [0 0 1200 600])
subplot(1,3,1)
plotMumShah(parabolas_signal,parabolas_changePoints)
title('Clean "parabolas" signal')
ylim(yAxisLim)
subplot(1,3,2)
plot(data,'.')
title('Noisy data')
ylim(yAxisLim)
subplot(1,3,3)
plotMumShah(u,changePoints)
title('Pcw. quadratic reconstruction')
ylim(yAxisLim)