필터 지우기
필터 지우기

Pinhole camera model

조회 수: 11 (최근 30일)
Jakob Sørensen
Jakob Sørensen 2012년 5월 8일
댓글: PRATIBHA SHINDE 2018년 1월 24일
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