forked from arwankhoiruddin/direct_profilometry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirect_profilometry.m
121 lines (97 loc) · 2.14 KB
/
direct_profilometry.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
close all
clear
clc
nc = 255;
d = 100;
l = 80;
obj_height = 20;
std_noise = 4.5;
filtered = 1;
nave = 3;
az = -49; % azimuth
el = 28; % elevation
showfig = 1;
x = linspace(-nc/2, nc/2, nc);
% generate parabola surface
z = zeros(nc, nc);
for i=1:nc
for j=1:nc
z(i,j) = -((x(i)^2) + (x(j)^2));
end
end
mid = (max(max(z)) - min(min(z))) / 3;
z = z + mid;
z = (z / max(max(z))) * obj_height;
for i=1:nc
for j=1:nc
if z(i,j) < 0
z(i,j) = 0;
end
end
end
if showfig
figure, surf(z); shading interp; colormap(gray)
set(gca, 'FontSize', 14, 'XTick', 0:50:250, 'YTick', 0:50:250, 'ZTick', -20:10:20);
axis([0 255 0 255 -10 30]);
view(az, el);
xlabel('x');
ylabel('y');
zlabel('height (mm)');
end
% generate reference pattern
ref = zeros(nc,nc);
for i=1:nc
for j=1:nc
ref(i,j) = j;
end
end
% add AWGN
ref = ref + std_noise*randn(nc,nc);
if showfig
figure, imshow(ref,[]);
end
% generate deformed pattern
def = zeros(nc,nc);
u = zeros(nc, nc);
for i=1:nc
for j=1:nc
u(i,j) = (d*z(i,j)) / (l - z(i,j));
def(i,j) = j + u(i,j);
end
end
% add AWGN
def = def + std_noise*randn(nc,nc);
if showfig
figure, imshow(def, []);
end
% filter first
if filtered
h = fspecial('average', [nave nave]);
def = imfilter(def, h, 'replicate');
ref = imfilter(ref, h, 'replicate');
def = medfilt2(def, [nave nave]);
ref = medfilt2(ref, [nave nave]);
end
% reconstruct using linear profilometry
tic
fx = def - ref;
toc
rec = (fx * l) ./ (d + fx);
dif = rec - z;
disp(['standard deviation of error: ' num2str(std(dif(:)))]);
if showfig
figure, surf(rec); shading interp; colormap(gray);
set(gca, 'FontSize', 14, 'XTick', 0:50:250, 'YTick', 0:50:250, 'ZTick', -20:10:20);
axis([0 255 0 255 -10 30]);
view(az, el);
xlabel('x');
ylabel('y');
zlabel('height (mm)');
figure, surf(rec - z); shading interp; colormap(gray);
set(gca, 'FontSize', 14, 'XTick', 0:50:250, 'YTick', 0:50:250, 'ZTick', -20:10:20);
axis([0 255 0 255 -10 30]);
view(az, el);
xlabel('x');
ylabel('y');
zlabel('height (mm)');
end