source: trunk/src/px_XYZ.m

Last change on this file was 1127, checked in by g7moreau, 4 months ago

Update Joel email

File size: 2.9 KB
RevLine 
[109]1%'px_XYZ': transform physical to image coordinates.
2%------------------------------------------------------------------------
3%[X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
4%------------------------------------------------------------------------           
5% OUTPUT:
6% [X,Y]: image coordinates(in pixels)
7%------------------------------------------------------------------------
8% INPUT:
9% Calib: structure containing calibration parameters
10% Xphys,Yphys,Zphys; vectors of physical coordinates for a set of points
[40]11
[809]12%=======================================================================
[1126]13% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]14%   http://www.legi.grenoble-inp.fr
[1127]15%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[809]16%
17%     This file is part of the toolbox UVMAT.
18%
19%     UVMAT is free software; you can redistribute it and/or modify
20%     it under the terms of the GNU General Public License as published
21%     by the Free Software Foundation; either version 2 of the license,
22%     or (at your option) any later version.
23%
24%     UVMAT is distributed in the hope that it will be useful,
25%     but WITHOUT ANY WARRANTY; without even the implied warranty of
26%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27%     GNU General Public License (see LICENSE.txt) for more details.
28%=======================================================================
29
[1112]30function [X,Y]=px_XYZ(Calib,Slice,Xphys,Yphys,Zphys)
[40]31if ~exist('Zphys','var')
32    Zphys=0;
33end
[114]34if ~isfield(Calib,'fx_fy')
35     Calib.fx_fy=[1 1];
[84]36end
[114]37if ~isfield(Calib,'Tx_Ty_Tz')
38     Calib.Tx_Ty_Tz=[0 0 1];
[84]39end
[114]40
[40]41%%%%%%%%%%%%%
[1112]42if isempty(Slice)
43    Slice=Calib;
44end
[542]45% general case
[40]46if isfield(Calib,'R')
47    R=(Calib.R)';
[542]48    %correct z for refraction if needed
[1112]49    if isfield(Slice,'InterfaceCoord') && isfield(Slice,'RefractionIndex')
50        H=Slice.InterfaceCoord(3);
[542]51        if H>Zphys
[1112]52            Zphys=H-(H-Zphys)/Slice.RefractionIndex; %corrected z (virtual object)Calib
[1111]53           
[892]54          %  test_refraction=1;
[542]55        end
56    end
57   
[114]58    %camera coordinates
[1113]59    Zphys=Zphys;%flip z coordinates
[114]60    xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx_Ty_Tz(1);
61    yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Tx_Ty_Tz(2);
62    zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tx_Ty_Tz(3);
[542]63   
64    %undistorted image coordinates
[114]65    Xu=xc./zc;
66    Yu=yc./zc;
[542]67   
68    %radial quadratic correction factor
[114]69    if ~isfield(Calib,'kc')
70        r2=1; %no quadratic distortion
[1115]71    elseif numel(Calib.kc)==1
72        r2=1+Calib.kc*(Xu.*Xu+Yu.*Yu);
[114]73    else
[1115]74        R2=Xu.*Xu+Yu.*Yu;
75        r2=1+Calib.kc(1)*R2+Calib.kc(2)*R2.*R2;
[114]76    end
[542]77   
78    %pixel coordinates
[114]79    if ~isfield(Calib,'Cx_Cy')
80        Calib.Cx_Cy=[0 0];%default value
81    end
82    X=Calib.fx_fy(1)*Xu.*r2+Calib.Cx_Cy(1);
[542]83    Y=Calib.fx_fy(2)*Yu.*r2+Calib.Cx_Cy(2); 
84   
85%case 'rescale'   
86else
[114]87    X=Calib.fx_fy(1)*(Xphys+Calib.Tx_Ty_Tz(1));
88    Y=Calib.fx_fy(2)*(Yphys+Calib.Tx_Ty_Tz(2)); 
[92]89end
90
91
92
Note: See TracBrowser for help on using the repository browser.