-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhotometricStereo.m
99 lines (77 loc) · 2.29 KB
/
PhotometricStereo.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
%% DETERMINING LIGHTING DIRECTION
%Using the mask first Sphere to determine Light direction.
%Uncomment this and use your mask
%filename=('pathtomask1');
%Function for calculating the location of sphere center and radius
[Maskrowcenter,Maskcolcenter,Maskradius] = image_mask_center(filename);
%Function for finding Highlight point
[s] = RGB_bright_point(filename);
%Function for Calulating the Normal
N = Normal_Sphere(Maskrowcenter,Maskcolcenter,Maskradius,s);
%Using the normal to calculate the lighting direction at R = [0 0 1]'
R=[0 0 1]';
L_Sp_1=zeros(3,length(Filelist));
for i=1:length(N)
L_Sphere_1 = 2*dot(N(:,i),R)*N(:,i)-R;
L_Sp_1(:,i)=L_Sphere_1;
end
L_Sp_1;
%Using mask of second sphere
%filename=(pathtomask2);
[Maskrowcenter,Maskcolcenter,Maskradius] = image_mask_center(filename);
[s] = RGB_bright_point(filename);
N = Normal_Sphere(Maskrowcenter,Maskcolcenter,Maskradius,s);
R=[0 0 1]';
L_Sp_2=zeros(3,length(Filelist));
for j=1:length(N)
L_Sphere_2 = 2*dot(N(:,j),R)*N(:,j)-R;
L_Sp_2(:,j)=L_Sphere_2;
end
L_Sp_2;
% Using Lambertian Sphere where Light direction is equal to Normal
%filename=('pathtointensitymask');
[Maskrowcenter,Maskcolcenter,Maskradius] = image_mask_center(filename);
[s] = RGB_bright_point(filename);
N = Normal_Sphere(Maskrowcenter,Maskcolcenter,Maskradius,s);
L_lamb=zeros(3,length(Filelist));
for k =1:length(N)
L_Lambertian = N(:,k);
L_lamb(:,k)=L_Lambertian;
end
L_lamb;
%% Estimation of Normal
filename=('applemask.png');
[p] = Intensity(filename);
[x,y] = image_mask(filename);
%Storing the pixels of all images
results=zeros(length(Filelist),length([x,y]));
for k=1:22
for i=1:length([x,y])
results(k,i)=p(x(i),y(i),k);
end
end
G=((results)'*L_Sp_2')*inv((L_Sp_2*L_Sp_2'));
kd=sqrt(G(:,1).^2 + G(:,2).^2 + G(:,3).^2);
Nd=zeros(length([x,y]),3);
for i=1:3
for j=1:34132
Nd(j,i)=(1/kd(j)).*G(j,i);
end
end
Nd;
surf_n1=zeros(600,800,3);
for k=1:3
for i=1:length([x,y])
surf_n1(x(i),y(i),k)=Nd(i,k); %3*34132
end
end
surf_albedo=zeros(600,800,1);
for k=1:1
for i=1:length([x,y])
surf_albedo(x(i),y(i),k)=kd(i,k); %3*34132
end
end
subplot(1,2,1);
imshow(surf_n1);
subplot(1,2,2);
imshow(10*surf_albedo);