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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
clear all;
close all;
%Generation of the fiber in 3D
lambda = 5;
a = 1;
b = lambda * a;
center = [7.5 30 -30];
[x, y, z] = ellipsoid(center(1),center(2),center(3),b,a,a);
S = surfl(x,y,z);
S.FaceColor = 'black';
S.EdgeColor = 'black';
rotate(S, [1 0 0], 0, center);
rotate(S, [0 1 0], 45, center);
rotate(S, [0 0 1], 75, center);
%set(gca,'xtick',[],'ytick',[],'ztick',[])
%set(gca,'color','k') % pour le fond
%set(gcf,'color','k') % pour les bordures
xlabel('X')
ylabel('Y')
zlabel('Z')
axis equal
set(gca,'xlim',[0 15])
set(gca,'ylim',[0 60])
set(gca,'zlim',[-60 0])
%Coordinates of the fiber points
Matrix_X = S.XData;
Matrix_Y = S.YData;
Matrix_Z = S.ZData;
X = Matrix_X(:);
Y = Matrix_Y(:);
Z = Matrix_Z(:);
sizeX = size(X);
%Definition of the extrinsic matrix
beta = 20;
a1 = pi/180*[0 beta 0];
a2 = pi/180*[0 -beta 0];
a3 = pi/180*[0 0 0];
a4 = pi/180*[-beta 0 0];
rotm1 = eul2rotm(a1,'XYZ');
rotm2 = eul2rotm(a2,'XYZ');
rotm3 = eul2rotm(a3,'XYZ');
rotm4 = eul2rotm(a4,'XYZ');
t1 = [-150;50;500];
t2 = [250;50;500];
t3 = [50;50;500];
t4 = [50;250;1000];
%Definition of the intrinsic matrix
f = 50; %mm focal length
sp = 0.01; %size of one pixel in mm
fx = f/sp; %focal length in pixels
fy = f/sp; %focal length in pixels
% r = 0.254; %resolution in pixels/inch
% sx = r/25.4; %resolution in pixels/mm
% sy = r/25.4; %resolution in pixels/mm
w = 1500; %width of the image in pixels
W = w*sp; %width of the digital sensor in mm
h = 1000; %height of the image in pixels
H = h*sp; %height of the digital sensor in mm
s = 0; %axis skew
x0 = 0; %offset point x in pixels
y0 = 0; %offset point y in pixels
Fx = fx*W/w ; %focal length x in mm
Fy = fx*H/h ; %focal length y in mm
X0 = x0*W/w; %offset point x in mm
Y0 = y0*H/h; %offset point y in mm
K = [Fx s X0;0 Fy Y0;0 0 1];
%Camera Matrix
M1 = [rotm1 t1];
M2 = [rotm2 t2];
M3 = [rotm3 t3];
M4 = [rotm4 t4];
P1 = K * M1;
P2 = K * M2;
P3 = K * M3;
P4 = K * M4;
I1 = zeros(3,sizeX(1));
I2 = zeros(3,sizeX(1));
I3 = zeros(3,sizeX(1));
I4 = zeros(3,sizeX(1));
for i=1:sizeX(1)
O = [X(i,1);Y(i,1);Z(i,1);1];
I1(:,i) = P1 * O;
I2(:,i) = P2 * O;
I3(:,i) = P3 * O;
I4(:,i) = P4 * O;
end
x1 = zeros(sizeX(1),1);
x2 = zeros(sizeX(1),1);
x3 = zeros(sizeX(1),1);
x4 = zeros(sizeX(1),1);
y1 = zeros(sizeX(1),1);
y2 = zeros(sizeX(1),1);
y3 = zeros(sizeX(1),1);
y4 = zeros(sizeX(1),1);
for i=1:sizeX(1)
x1(i) = 1/sp*(I1(1,i)/I1(3,i));
y1(i) = 1/sp*(I1(2,i)/I1(3,i));
x2(i) = 1/sp*(I2(1,i)/I2(3,i));
y2(i) = 1/sp*(I2(2,i)/I2(3,i));
x3(i) = 1/sp*(I3(1,i)/I3(3,i));
y3(i) = 1/sp*(I3(2,i)/I3(3,i));
x4(i) = 1/sp*(I4(1,i)/I4(3,i));
y4(i) = 1/sp*(I4(2,i)/I4(3,i));
end
% %% Image for Camera1
%
% fig1 = figure(2);
% X1 = vec2mat(x1,21);
% Y1 = vec2mat(y1,21);
% contourf(X1,Y1,Y1,'w');
% colormap([1 1 1])
% %axis equal
% set(gca,'xlim',[0 1500])
% set(gca,'ylim',[0 1000])
% %set(gca,'xtick',[],'ytick',[],'ztick',[])
% set(gca,'color','k') % pour le fond
% %set(gcf,'color','k') % pour les bordures
% %grid off
% %axis off
% %print(fig1, 'Image_1', '-depsc', '-r600')
%
% %% Image for Camera2
%
% fig2 = figure(3);
% X2 = vec2mat(x2,21);
% Y2 = vec2mat(y2,21);
% contourf(X2,Y2,Y2,'w');
% colormap([1 1 1])
% %axis equal
% set(gca,'xlim',[0 1500])
% set(gca,'ylim',[0 1000])
% %set(gca,'xtick',[],'ytick',[],'ztick',[])
% set(gca,'color','k') % pour le fond
% %set(gcf,'color','k') % pour les bordures
% %grid off
% %axis off
% %print(fig2, 'Image_2', '-depsc', '-r600')
%% Image for Camera3
fig3 = figure(4);
X3 = vec2mat(x3,21);
Y3 = vec2mat(y3,21);
contourf(X3,Y3,Y3,'w');
colormap([1 1 1])
axis equal
%axis equal
set(gca,'xlim',[0 1500])
set(gca,'ylim',[0 1000])
%set(gca,'xtick',[],'ytick',[],'ztick',[])
set(gca,'color','k') % pour le fond
%set(gcf,'color','k') % pour les bordures
%grid off
%axis off
%print(fig3, 'Image_3', '-depsc', '-r600')
% %% Image for Camera4
%
% fig4 = figure(5);
% X4 = vec2mat(x4,21);
% Y4 = vec2mat(y4,21);
% contourf(X4,Y4,Y4,'w');
% colormap([1 1 1])
% axis equal
% set(gca,'xlim',[0 1500])
% set(gca,'ylim',[0 1000])
% %set(gca,'xtick',[],'ytick',[],'ztick',[])
% set(gca,'color','k') % pour le fond
% %set(gcf,'color','k') % pour les bordures
% %grid off
% %axis off
% %print(fig4, 'Image_4', '-depsc', '-r600') |
Partager