Pinhole camera model

18 次查看(过去 30 天)
Jakob Sørensen
Jakob Sørensen 2012-5-8
I'm working on a pinhole camera model which is supposed to sample a 3D volume. I want to choose a view axis, which should be perpendicular on the side surface of the volume (preferarble on the ZX-plane), and goes through (0,0,0) which is located inside the volume (which is cubic). Then calculate the remaining sample points as a function of the view axis, as well as a focal length. Finally the sample points needs to be redefined from Cartesian cords, to some sort of pseudo polar cords (don't worry, that part is correct). The code is as following
% Apply constants
d = 3;
f = 5;
res = 100;
% Define axis
ax = linspace(-0.06,0.06,1128);
ay = linspace(-pi/4,pi/4,60);
az = linspace(-pi/4,pi/4,60);
% Load image and rename
load('3D_wire_fixed.mat')
im = HRI_3D;
% Make meshgrid (first step of creating sampling points)
xgrid = linspace(-0.1,0.1,res);
ygrid = linspace(-0.1,0.1,res);
zgrid = linspace(-0.1,0.1,res);
[XI, YI, ZI] = meshgrid(xgrid, ygrid, zgrid);
% Calculate view lines (second step of creating sampling points)
XO = (-XI/f).*(d+YI);
ZO = (-ZI/f).*(d+YI);
% Create rotation matrin (used to change viewpoint).
% When a and b is both 0, no rotation is applied.
a = 0; b = 0;
R = [cosd(b) sind(a)*sind(b) cosd(a)*sind(b)
0 cosd(a) -sind(a)
-sind(b) cosd(b)*sind(a) cosd(a)*cosd(b)];
% Gather in 3xN array
XYZ = [XO(:) YI(:) ZO(:)];
% Rotating samplepoints
XYZ = R * XYZ';
% Translating samplepoints
x = XYZ(1,:);
y = XYZ(2,:);
z = XYZ(3,:);
% Making the transformed Vectors to 3- Matrix's
xpts = reshape(x(:), res, res, res);
ypts = reshape(y(:), res, res, res);
zpts = reshape(z(:), res, res, res);
% Transform from cartesian coords to double circular coords
zy_sp = atan2(ypts,zpts);
zx_sp = atan2(xpts,zpts);
r_sp = sqrt(xpts.^2 + ypts.^2 + zpts.^2);
% Interpolate image using the above information
int_img = interp3(ay, ax, az, im, zy_sp, r_sp, zx_sp);
int_img(isnan(int_img)) = -120;
img = squeeze(max(int_img,[],1));
  2 个评论
Image Analyst
Image Analyst 2012-5-8
OK, though the File Exchange would be the best place for this code (once you have it finished and if you think it could be generally useful to other people).
PRATIBHA SHINDE
PRATIBHA SHINDE 2018-1-24
It is showing an error for 'load('3D_wire_fixed.mat')'.

请先登录,再进行评论。

回答(1 个)

Jakob Sørensen
Jakob Sørensen 2012-5-8
Woops, I think I hadn't had enough coffee when I wrote this. The thing is, that it's not working correctly. There should be some pretty clear white lines inside the object, but they don't show up, so there is something wrong with the code...

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for USB Webcams 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by