1 | % visualize_distortions
|
---|
2 | %
|
---|
3 | %
|
---|
4 | % A script to run in conjunction with calib_gui in TOOLBOX_calib to plot
|
---|
5 | % the distortion models.
|
---|
6 | %
|
---|
7 | % This is a slightly modified version of the script plot_CCT_distortion.m written by Mr. Oshel
|
---|
8 | % Thank you Mr. Oshel for your contribution!
|
---|
9 |
|
---|
10 |
|
---|
11 | [mx,my] = meshgrid(0:nx/20:(nx-1),0:ny/20:(ny-1));
|
---|
12 | [nnx,nny]=size(mx);
|
---|
13 | px=reshape(mx',nnx*nny,1);
|
---|
14 | py=reshape(my',nnx*nny,1);
|
---|
15 | kk_new=[fc(1) alpha_c*fc(1) cc(1);0 fc(2) cc(2);0 0 1];
|
---|
16 | rays=inv(kk_new)*[px';py';ones(1,length(px))];
|
---|
17 | x=[rays(1,:)./rays(3,:);rays(2,:)./rays(3,:)];
|
---|
18 |
|
---|
19 |
|
---|
20 | title2=strcat('Complete Distortion Model');
|
---|
21 |
|
---|
22 | fh1 = 2;
|
---|
23 |
|
---|
24 | %if ishandle(fh1),
|
---|
25 | % close(fh1);
|
---|
26 | %end;
|
---|
27 | figure(fh1); clf;
|
---|
28 | xd=apply_distortion(x,kc);
|
---|
29 | px2=fc(1)*(xd(1,:)+alpha_c*xd(2,:))+cc(1);
|
---|
30 | py2=fc(2)*xd(2,:)+cc(2);
|
---|
31 | dx=px2-px';
|
---|
32 | dy=py2-py';
|
---|
33 | Q=quiver(px+1,py+1,dx,dy);
|
---|
34 | hold on;
|
---|
35 | plot(cc(1)+1,cc(2)+1,'o');
|
---|
36 | plot((nx-1)/2+1,(ny-1)/2+1,'x');
|
---|
37 | dr=reshape(sqrt((dx.*dx)+(dy.*dy)),nny,nnx)';
|
---|
38 | [C,h]=contour(mx,my,dr,'k');
|
---|
39 | clabel(C,h);
|
---|
40 | Mean=mean(mean(dr));
|
---|
41 | Max=max(max(dr));
|
---|
42 | title(title2);
|
---|
43 |
|
---|
44 | axis ij;
|
---|
45 | axis([1 nx 1 ny])
|
---|
46 | axis equal;
|
---|
47 | axis tight;
|
---|
48 |
|
---|
49 | position=get(gca,'Position');
|
---|
50 | shr = 0.9;
|
---|
51 | position(1)=position(1)+position(3)*((1-shr)/2);
|
---|
52 | position(2)=position(2)+position(4)*(1-shr)+0.03;
|
---|
53 | position(3:4)=position(3:4)*shr;
|
---|
54 | set(gca,'position',position);
|
---|
55 | set(gca,'fontsize',8,'fontname','clean')
|
---|
56 |
|
---|
57 | gh = gca;
|
---|
58 |
|
---|
59 | line1=sprintf('Principal Point = (%0.6g, %0.6g)',cc(1),cc(2));
|
---|
60 | line2=sprintf('Focal Length = (%0.6g, %0.6g)',fc(1),fc(2));
|
---|
61 | line3=sprintf('Radial coefficients = (%0.4g, %0.4g, %0.4g)',kc(1),kc(2),kc(5));
|
---|
62 | line4=sprintf('Tangential coefficients = (%0.4g, %0.4g)',kc(3),kc(4));
|
---|
63 | line5=sprintf('+/- [%0.4g, %0.4g]',cc_error(1),cc_error(2));
|
---|
64 | line6=sprintf('+/- [%0.4g, %0.4g]',fc_error(1),fc_error(2));
|
---|
65 | line7=sprintf('+/- [%0.4g, %0.4g, %0.4g]',kc_error(1),kc_error(2),kc_error(5));
|
---|
66 | line8=sprintf('+/- [%0.4g, %0.4g]',kc_error(3),kc_error(4));
|
---|
67 | line9=sprintf('Pixel error = [%0.4g, %0.4g]',err_std(1),err_std(2));
|
---|
68 | line10=sprintf('Skew = %0.4g',alpha_c);
|
---|
69 | line11=sprintf('+/- %0.4g',alpha_c_error);
|
---|
70 |
|
---|
71 |
|
---|
72 | axes('position',[0 0 1 1],'visible','off');
|
---|
73 | th=text(0.11,0,{line9,line2,line1,line10,line3,line4},'horizontalalignment','left','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
74 | th2=text(0.9,0.,{line6,line5,line11,line7,line8},'horizontalalignment','right','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
75 | %set(th,'FontName','fixed');
|
---|
76 | axes(gh);
|
---|
77 |
|
---|
78 | set(fh1,'color',[1,1,1]);
|
---|
79 |
|
---|
80 | hold off;
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 | title2=strcat('Tangential Component of the Distortion Model');
|
---|
87 |
|
---|
88 | fh2 = 3;
|
---|
89 |
|
---|
90 | %if ishandle(fh2),
|
---|
91 | % close(fh2);
|
---|
92 | %end;
|
---|
93 | figure(fh2); clf;
|
---|
94 | xd=apply_distortion(x,[0 0 kc(3) kc(4) 0]);
|
---|
95 | px2=fc(1)*(xd(1,:)+alpha_c*xd(2,:))+cc(1);
|
---|
96 | py2=fc(2)*xd(2,:)+cc(2);
|
---|
97 | dx=px2-px';
|
---|
98 | dy=py2-py';
|
---|
99 | Q=quiver(px+1,py+1,dx,dy);
|
---|
100 | hold on;
|
---|
101 | plot(cc(1)+1,cc(2)+1,'o');
|
---|
102 | plot((nx-1)/2+1,(ny-1)/2+1,'x');
|
---|
103 | dr=reshape(sqrt((dx.*dx)+(dy.*dy)),nny,nnx)';
|
---|
104 | [C,h]=contour(mx,my,dr,'k');
|
---|
105 | % clabel(C,h);
|
---|
106 | Mean=mean(mean(dr));
|
---|
107 | Max=max(max(dr));
|
---|
108 | title(title2);
|
---|
109 |
|
---|
110 | axis ij;
|
---|
111 | axis([1 nx 1 ny])
|
---|
112 | axis equal;
|
---|
113 | axis tight;
|
---|
114 |
|
---|
115 | position=get(gca,'Position');
|
---|
116 | shr = 0.9;
|
---|
117 | position(1)=position(1)+position(3)*((1-shr)/2);
|
---|
118 | position(2)=position(2)+position(4)*(1-shr)+0.03;
|
---|
119 | position(3:4)=position(3:4)*shr;
|
---|
120 | set(gca,'position',position);
|
---|
121 | set(gca,'fontsize',8,'fontname','clean')
|
---|
122 |
|
---|
123 | gh = gca;
|
---|
124 |
|
---|
125 | line1=sprintf('Principal Point = (%0.6g, %0.6g)',cc(1),cc(2));
|
---|
126 | line2=sprintf('Focal Length = (%0.6g, %0.6g)',fc(1),fc(2));
|
---|
127 | line3=sprintf('Radial coefficients = (%0.4g, %0.4g, %0.4g)',kc(1),kc(2),kc(5));
|
---|
128 | line4=sprintf('Tangential coefficients = (%0.4g, %0.4g)',kc(3),kc(4));
|
---|
129 | line5=sprintf('+/- [%0.4g, %0.4g]',cc_error(1),cc_error(2));
|
---|
130 | line6=sprintf('+/- [%0.4g, %0.4g]',fc_error(1),fc_error(2));
|
---|
131 | line7=sprintf('+/- [%0.4g, %0.4g, %0.4g]',kc_error(1),kc_error(2),kc_error(5));
|
---|
132 | line8=sprintf('+/- [%0.4g, %0.4g]',kc_error(3),kc_error(4));
|
---|
133 | line9=sprintf('Pixel error = [%0.4g, %0.4g]',err_std(1),err_std(2));
|
---|
134 | line10=sprintf('Skew = %0.4g',alpha_c);
|
---|
135 | line11=sprintf('+/- %0.4g',alpha_c_error);
|
---|
136 |
|
---|
137 |
|
---|
138 | axes('position',[0 0 1 1],'visible','off');
|
---|
139 | th=text(0.11,0,{line9,line2,line1,line10,line3,line4},'horizontalalignment','left','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
140 | th2=text(0.9,0.,{line6,line5,line11,line7,line8},'horizontalalignment','right','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
141 | %set(th,'FontName','fixed');
|
---|
142 | axes(gh);
|
---|
143 |
|
---|
144 | set(fh2,'color',[1,1,1]);
|
---|
145 |
|
---|
146 | hold off;
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 | title2=strcat('Radial Component of the Distortion Model');
|
---|
156 |
|
---|
157 | fh3 = 4;
|
---|
158 |
|
---|
159 | %if ishandle(fh3),
|
---|
160 | % close(fh3);
|
---|
161 | %end;
|
---|
162 | figure(fh3); clf;
|
---|
163 | xd=apply_distortion(x,[kc(1) kc(2) 0 0 kc(5)]);
|
---|
164 | px2=fc(1)*(xd(1,:)+alpha_c*xd(2,:))+cc(1);
|
---|
165 | py2=fc(2)*xd(2,:)+cc(2);
|
---|
166 | dx=px2-px';
|
---|
167 | dy=py2-py';
|
---|
168 | Q=quiver(px+1,py+1,dx,dy);
|
---|
169 | hold on;
|
---|
170 | plot(cc(1)+1,cc(2)+1,'o');
|
---|
171 | plot((nx-1)/2+1,(ny-1)/2+1,'x');
|
---|
172 | dr=reshape(sqrt((dx.*dx)+(dy.*dy)),nny,nnx)';
|
---|
173 | [C,h]=contour(mx,my,dr,'k');
|
---|
174 | clabel(C,h);
|
---|
175 | Mean=mean(mean(dr));
|
---|
176 | Max=max(max(dr));
|
---|
177 | title(title2);
|
---|
178 |
|
---|
179 | axis ij;
|
---|
180 | axis([1 nx 1 ny])
|
---|
181 | axis equal;
|
---|
182 | axis tight;
|
---|
183 |
|
---|
184 | position=get(gca,'Position');
|
---|
185 | shr = 0.9;
|
---|
186 | position(1)=position(1)+position(3)*((1-shr)/2);
|
---|
187 | position(2)=position(2)+position(4)*(1-shr)+0.03;
|
---|
188 | position(3:4)=position(3:4)*shr;
|
---|
189 | set(gca,'position',position);
|
---|
190 | set(gca,'fontsize',8,'fontname','clean')
|
---|
191 |
|
---|
192 | gh = gca;
|
---|
193 |
|
---|
194 | line1=sprintf('Principal Point = (%0.6g, %0.6g)',cc(1),cc(2));
|
---|
195 | line2=sprintf('Focal Length = (%0.6g, %0.6g)',fc(1),fc(2));
|
---|
196 | line3=sprintf('Radial coefficients = (%0.4g, %0.4g, %0.4g)',kc(1),kc(2),kc(5));
|
---|
197 | line4=sprintf('Tangential coefficients = (%0.4g, %0.4g)',kc(3),kc(4));
|
---|
198 | line5=sprintf('+/- [%0.4g, %0.4g]',cc_error(1),cc_error(2));
|
---|
199 | line6=sprintf('+/- [%0.4g, %0.4g]',fc_error(1),fc_error(2));
|
---|
200 | line7=sprintf('+/- [%0.4g, %0.4g, %0.4g]',kc_error(1),kc_error(2),kc_error(5));
|
---|
201 | line8=sprintf('+/- [%0.4g, %0.4g]',kc_error(3),kc_error(4));
|
---|
202 | line9=sprintf('Pixel error = [%0.4g, %0.4g]',err_std(1),err_std(2));
|
---|
203 | line10=sprintf('Skew = %0.4g',alpha_c);
|
---|
204 | line11=sprintf('+/- %0.4g',alpha_c_error);
|
---|
205 |
|
---|
206 |
|
---|
207 | axes('position',[0 0 1 1],'visible','off');
|
---|
208 | th=text(0.11,0,{line9,line2,line1,line10,line3,line4},'horizontalalignment','left','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
209 | th2=text(0.9,0.,{line6,line5,line11,line7,line8},'horizontalalignment','right','verticalalignment','bottom','fontsize',8,'fontname','clean');
|
---|
210 | %set(th,'FontName','fixed');
|
---|
211 | axes(gh);
|
---|
212 |
|
---|
213 | set(fh3,'color',[1,1,1]);
|
---|
214 |
|
---|
215 | hold off;
|
---|
216 |
|
---|
217 | figure(fh1);
|
---|