Pinhole camera model
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 8 Mag 2012
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).
Risposte (1)
Vedere anche
Categorie
Scopri di più su MATLAB Support Package for USB Webcams in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!