source: trunk/src/px_XYZ.m @ 1201

Last change on this file since 1201 was 1201, checked in by sommeria, 5 hours ago

various improvements...

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