Differences between 2D and 3D transformations

本文详细介绍了2D和3D空间中的基本几何变换,包括平移、旋转和缩放。对于2D平移,通过(x', y')坐标表示平移向量(tx, ty),3D平移则增加了tz轴的平移距离。2D旋转围绕原点或任意点进行,涉及旋转角度和旋转中心;3D旋转则涉及到绕x、y、z轴的旋转。至于缩放,2D和3D中都区分了固定点为原点和平移点的情况,分别给出了相应的变换矩阵和公式。这些变换在图形学、计算机视觉和游戏开发等领域有广泛应用。

Differences between 2D and 3D transformations

1. Translation

1.1 2D Translation

在这里插入图片描述

FIGURE-1 2D Translation
  • Translation distances: t x t_{x} tx and t y t_{y} ty .

  • Original coordinate position: ( x , y ) (x,y) (x,y) .

  • New coordinate position: ( x ′ , y ′ ) (x',y') (x,y) .

  • x ′ = x + t x , y ′ = y + t y x'=x+t_{x}, \quad\quad y'=y+t_{y} x=x+tx,y=y+ty .

  • Translation vector: ( t x , t y ) (t_{x}, t_{y}) (tx,ty) .

  • Translation matrix:

  • P = [ x y ] , P ′ = [ x ′ y ′ ] , T = [ t x t y ] P ′ = P + T \mathbf{P}=\left[\begin{array}{l} x \\ y \end{array}\right], \quad \mathbf{P}^{\prime}=\left[\begin{array}{l} x^{\prime} \\ y^{\prime} \end{array}\right], \quad \mathbf{T}=\left[\begin{array}{l} t_x \\ t_y \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{P}+\mathbf{T} P=[xy],P=[xy],T=[txty]P=P+T

  • 2D translation transformation equations:

  • [ x ′ y ′ 1 ] = [ 1 0 t x 0 1 t y 0 0 1 ] ⋅ [ x y 1 ] P ′ = T ( t x , t y ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{lll} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{T}\left(t_x, t_y\right) \cdot \mathbf{P} xy1=100010txty1xy1P=T(tx,ty)P

1.2 3D Translation

在这里插入图片描述

FIGURE-2 3D Translation
  • Translation distances: t x , t y , t z t_{x}, \quad t_{y}, \quad t_{z} tx,ty,tz .

  • Original coordinate position: ( x , y , z ) (x,y,z) (x,y,z) .

  • New coordinate position: ( x ′ , y ′ , z ′ ) (x',y',z') (x,y,z) .

  • x ′ = x + t x , y ′ = y + t y , z ′ = z + t z x'=x+t_{x}, \quad\quad y'=y+t_{y}, \quad\quad z'=z+t_{z} x=x+tx,y=y+ty,z=z+tz .

  • Translation vector: ( t x , t y , t z ) (t_{x}, t_{y}, t_{z}) (tx,ty,tz) .

  • 3D translation transformation equations:

  • [ x ′ y ′ z ′ 1 ] = [ 1 0 0 t x 0 1 0 t y 0 0 1 t z 0 0 0 1 ] ⋅ [ x y z 1 ] P ′ = T ⋅ P \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{cccc} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{T} \cdot \mathbf{P} xyz1=100001000010txtytz1xyz1P=TP

2. Rotation

2.1 2D Rotation

在这里插入图片描述

FIGURE-3 2D Rotation
  • Rotation point: ( x r , y r ) (x_{r}, y_{r}) (xr,yr) .

  • When the rotation point is the coordinate origin:

    • Rotate a point at position ( x , y ) (x,y) (x,y) through an angle θ \theta θ about the origin:

    • x ′ = x cos ⁡ θ − y sin ⁡ θ y ′ = x sin ⁡ θ + y cos ⁡ θ \begin{aligned} &x^{\prime}=x \cos \theta-y \sin \theta \\ &y^{\prime}=x \sin \theta+y \cos \theta \end{aligned} x=xcosθysinθy=xsinθ+ycosθ

    • Rotation matrix:

    • R = [ cos ⁡ θ − sin ⁡ θ sin ⁡ θ cos ⁡ θ ] P ′ = R ⋅ P \mathbf{R}=\left[\begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R} \cdot \mathbf{P} R=[cosθsinθsinθcosθ]P=RP

  • When the rotation point is not the coordinate origin:

    • Rotate a point from position ( x , y ) (x, y) (x,y) to position ( x ′ , y ′ ) \left(x^{\prime}, y^{\prime}\right) (x,y) through an angle θ \theta θ about rotation point ( x r , y r ) \left(x_r, y_r\right) (xr,yr):

    • x ′ = x r + ( x − x r ) cos ⁡ θ − ( y − y r ) sin ⁡ θ y ′ = y r + ( x − x r ) sin ⁡ θ + ( y − y r ) cos ⁡ θ \begin{aligned} &x^{\prime}=x_r+\left(x-x_r\right) \cos \theta-\left(y-y_r\right) \sin \theta \\ &y^{\prime}=y_r+\left(x-x_r\right) \sin \theta+\left(y-y_r\right) \cos \theta \end{aligned} x=xr+(xxr)cosθ(yyr)sinθy=yr+(xxr)sinθ+(yyr)cosθ

  • 2D rotation transformation equations:

  • [ x ′ y ′ 1 ] = [ cos ⁡ θ − sin ⁡ θ 0 sin ⁡ θ cos ⁡ θ 0 0 0 1 ] ⋅ [ x y 1 ] P ′ = R ( θ ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{ccc} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R}(\theta) \cdot \mathbf{P} xy1=cosθsinθ0sinθcosθ0001xy1P=R(θ)P

2.2 3D Rotation

在这里插入图片描述

FIGURE-4 3D Rotation
  • Rotation axis: x − a x i s , y − a x i s , z − a x i s x-axis, \quad y-axis, \quad z-axis xaxis,yaxis,zaxis .

  • If the rotation axis is z − a x i s z-axis zaxis:

    • x ′ = x cos ⁡ θ − y sin ⁡ θ y ′ = x sin ⁡ θ + y cos ⁡ θ z ′ = z \begin{aligned} &x^{\prime}=x \cos \theta-y \sin \theta \\ &y^{\prime}=x \sin \theta+y \cos \theta \\ &z^{\prime}=z \end{aligned} x=xcosθysinθy=xsinθ+ycosθz=z

    • 3D rotation transformation equations:

    • [ x ′ y ′ z ′ 1 ] = [ cos ⁡ θ − sin ⁡ θ 0 0 sin ⁡ θ cos ⁡ θ 0 0 0 0 1 0 0 0 0 1 ] ⋅ [ x y z 1 ] P ′ = R z ( θ ) ⋅ P \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{cccc} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ z \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{R}_z(\theta) \cdot \mathbf{P} xyz1=cosθsinθ00sinθcosθ0000100001xyz1P=Rz(θ)P

  • 3D rotation transformation equations about an axis that is parallel to the x − a x i s x-axis xaxis .

    • P ′ = T − 1 ⋅ R x ( θ ) ⋅ T ⋅ P R ( θ ) = T − 1 ⋅ R x ( θ ) ⋅ T \mathbf{P}^{\prime}=\mathbf{T}^{-1} \cdot \mathbf{R}_x(\theta) \cdot \mathbf{T} \cdot \mathbf{P} \\\\ \mathbf{R}(\theta)=\mathbf{T}^{-1} \cdot \mathbf{R}_x(\theta) \cdot \mathbf{T} P=T1Rx(θ)TPR(θ)=T1Rx(θ)T
  • 3D rotation transformation equations about an axis that is not parallel to any axes:

    • V = P 2 − P 1 = ( x 2 − x 1 , y 2 − y 1 , z 2 − z 1 ) \begin{aligned} \mathbf{V} &=\mathbf{P}_2-\mathbf{P}_1 \\ &=\left(x_2-x_1, y_2-y_1, z_2-z_1\right) \end{aligned} V=P2P1=(x2x1,y2y1,z2z1)

    • u = V ∣ V ∣ = ( a , b , c ) \mathbf{u}=\frac{\mathbf{V}}{|\mathbf{V}|}=(a, b, c) u=VV=(a,b,c)

    • a = x 2 − x 1 ∣ V ∣ , b = y 2 − y 1 ∣ V ∣ , c = z 2 − z 1 ∣ V ∣ a=\frac{x_2-x_1}{|\mathbf{V}|}, \quad b=\frac{y_2-y_1}{|\mathbf{V}|}, \quad c=\frac{z_2-z_1}{|\mathbf{V}|} a=Vx2x1,b=Vy2y1,c=Vz2z1

    • If the direction is P 1 → P 2 \mathbf{P_1} \rightarrow \mathbf{P_2} P1P2 , move P 1 \mathbf{P_1} P1 to the origin.

    • T = [ 1 0 0 − x 1 0 1 0 − y 1 0 0 1 − z 1 0 0 0 1 ] \mathbf{T}=\left[\begin{array}{cccc} 1 & 0 & 0 & -x_1 \\ 0 & 1 & 0 & -y_1 \\ 0 & 0 & 1 & -z_1 \\ 0 & 0 & 0 & 1 \end{array}\right] T=100001000010x1y1z11

    • Rotate the vector about the x − a x i s x-axis xaxis and into the x z xz xz plane:

    • R x ( α ) = [ 1 0 0 0 0 c d − b d 0 0 b d c d 0 0 0 0 1 ] \mathbf{R}_x(\alpha)=\left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & \frac{c}{d} & -\frac{b}{d} & 0 \\ 0 & \frac{b}{d} & \frac{c}{d} & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] Rx(α)=10000dcdb00dbdc00001

    • Then, rotate the vector about the y − a x i s y-axis yaxis and into the z − a x i s z-axis zaxis:

    • R y ( β ) = [ d 0 − a 0 0 1 0 0 a 0 d 0 0 0 0 1 ] \mathbf{R}_y(\beta)=\left[\begin{array}{cccc} d & 0 & -a & 0 \\ 0 & 1 & 0 & 0 \\ a & 0 & d & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] Ry(β)=d0a00100a0d00001

    • Finally, rotate the vector as the specified rotation angle θ \theta θ about the z − a x i s z-axis zaxis:

    • R z ( θ ) = [ cos ⁡ θ − sin ⁡ θ 0 0 sin ⁡ θ cos ⁡ θ 0 0 0 0 1 0 0 0 0 1 ] \mathbf{R}_z(\theta)=\left[\begin{array}{cccc} \cos \theta & -\sin \theta & 0 & 0 \\ \sin \theta & \cos \theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] Rz(θ)=cosθsinθ00sinθcosθ0000100001

    • The composition of these transformations:

    • R ( θ ) = T − 1 ⋅ R x − 1 ( α ) ⋅ R y − 1 ( β ) ⋅ R z ( θ ) ⋅ R y ( β ) ⋅ R x ( α ) ⋅ T \mathbf{R}(\theta)=\mathbf{T}^{-1} \cdot \mathbf{R}_x^{-1}(\alpha) \cdot \mathbf{R}_y^{-1}(\beta) \cdot \mathbf{R}_z(\theta) \cdot \mathbf{R}_y(\beta) \cdot \mathbf{R}_x(\alpha) \cdot \mathbf{T} R(θ)=T1Rx1(α)Ry1(β)Rz(θ)Ry(β)Rx(α)T

3. Scaling

3.1 2D Scaling

在这里插入图片描述

FIGURE-5 2D Scaling
  • Scaling factors: S x , S y S_x, \quad S_y Sx,Sy .

  • Object positions: ( x , y ) (x, y) (x,y) .

  • Transformed coordinates: ( x ′ , y ′ ) (x', y') (x,y) .

  • If the fixed point is the coordinate origin:

    • x ′ = x ⋅ s x , y ′ = y ⋅ s y x^{\prime}=x \cdot s_x, \quad y^{\prime}=y \cdot s_y x=xsx,y=ysy .

    • Scaling matrix:

    • [ x ′ y ′ ] = [ s x 0 0 s y ] ⋅ [ x y ] P ′ = S ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \end{array}\right]=\left[\begin{array}{cc} s_x & 0 \\ 0 & s_y \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{S} \cdot \mathbf{P} [xy]=[sx00sy][xy]P=SP

  • if the fixed point is ( x f , y f ) (x_f,y_f) (xf,yf) :

    • for ( x , y ) (x,y) (x,y) , the scaled coordinates ( x ′ , y ′ ) (x',y') (x,y) are:

    • x ′ − x f = ( x − x f ) s x , y ′ − y f = ( y − y f ) s y x^{\prime}-x_f=\left(x-x_f\right) s_x, \quad y^{\prime}-y_f=\left(y-y_f\right) s_y xxf=(xxf)sx,yyf=(yyf)sy

    • x ′ = x ⋅ s x + x f ( 1 − s x ) y ′ = y ⋅ s y + y f ( 1 − s y ) \begin{aligned} &x^{\prime}=x \cdot s_x+x_f\left(1-s_x\right) \\ &y^{\prime}=y \cdot s_y+y_f\left(1-s_y\right) \end{aligned} x=xsx+xf(1sx)y=ysy+yf(1sy)

  • 2D scaling transformation equations:

  • [ x ′ y ′ 1 ] = [ s x 0 0 0 s y 0 0 0 1 ] ⋅ [ x y 1 ] P ′ = S ( s x , s y ) ⋅ P \left[\begin{array}{l} x^{\prime} \\ y^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{ccc} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{l} x \\ y \\ 1 \end{array}\right] \\\\ \mathbf{P}^{\prime}=\mathbf{S}\left(s_x, s_y\right) \cdot \mathbf{P} xy1=sx000sy0001xy1P=S(sx,sy)P

3.2 3D Scaling

在这里插入图片描述

FIGURE-6 3D Scaling
  • Scaling factors: s x , s y , s z s_x, \quad s_y, \quad s_z sx,sy,sz .

  • Object positions: ( x , y , z ) (x, y,z) (x,y,z) .

  • Transformed coordinates: ( x ′ , y ′ , z ′ ) (x', y',z') (x,y,z) .

  • If the fixed point is the coordinate origin:

    • x ′ = x ⋅ s x , y ′ = y ⋅ s y , z ′ = z ⋅ s z x^{\prime}=x \cdot s_x, \quad y^{\prime}=y \cdot s_y, \quad z^{\prime}=z \cdot s_z x=xsx,y=ysy,z=zsz
  • 3D scaling transformation equations:

  • [ x ′ y ′ z ′ 1 ] = [ s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 ] ⋅ [ x y z 1 ] \left[\begin{array}{c} x^{\prime} \\ y^{\prime} \\ z^{\prime} \\ 1 \end{array}\right]=\left[\begin{array}{cccc} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{array}\right] \cdot\left[\begin{array}{c} x \\ y \\ z \\ 1 \end{array}\right] xyz1=sx0000sy0000sz00001xyz1

  • Construct a scaling transformation with respect to any fixed position ( x f , y f , z f ) (x_f,y_f,z_f) (xf,yf,zf) :

  • T ( x f , y f , z f ) ⋅ S ( s x , s y , s z ) ⋅ T ( − x f , − y f , − z f ) = [ s x 0 0 ( 1 − s x ) x f 0 s y 0 ( 1 − s y ) y f 0 0 s z ( 1 − s z ) z f 0 0 0 1 ] \mathbf{T}\left(x_f, y_f, z_f\right) \cdot \mathbf{S}\left(s_x, s_y, s_z\right) \cdot \mathbf{T}\left(-x_f,-y_f,-z_f\right)=\left[\begin{array}{cccc} s_x & 0 & 0 & \left(1-s_x\right) x_f \\ 0 & s_y & 0 & \left(1-s_y\right) y_f \\ 0 & 0 & s_z & \left(1-s_z\right) z_f \\ 0 & 0 & 0 & 1 \end{array}\right] T(xf,yf,zf)S(sx,sy,sz)T(xf,yf,zf)=sx0000sy0000sz0(1sx)xf(1sy)yf(1sz)zf1

* This example program shows how 128 images of the interior of a church can be * combined into a mosaic that covers a 360x130 degree view. The images were acquired * with a camera in which the exposure and white balance were set to automatic. * Therefore, there are very large brightness and color differences between the images. * Hence, adjust_mosaic_images is used to align the images radiometrically. * Furthermore, blending is used to hide the transitions between the individual * images that make up the mosaic. dev_update_off () dev_close_window () dev_open_window (0, 0, 978, 324, 'black', WindowHandle) dev_set_part (0, 0, 647, 1955) set_display_font (WindowHandle, 16, 'mono', 'true', 'false') dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Reading images...') * Read the 128 images that make up the mosaic. gen_empty_obj (Images) for J := 1 to 128 by 1 read_image (Image, 'panorama/sankt_martin_automatic_' + J$'03d') concat_obj (Images, Image, Images) endfor get_image_size (Image, Width, Height) * Construct the tuples that determine which images should be matched. The * mosaic images were acquired as 16 vertical strips of 8 images each. * For each image, we match the image below the current image in the same * strip and the image to the left of the current image in the adjacent strip. FF := [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8] TT := [2,9,3,10,4,11,5,12,6,13,7,14,8,15,16] From := [] To := [] for J := 0 to 15 by 1 From := [From,(FF - 1 + 8 * J) % 128 + 1] To := [To,(TT - 1 + 8 * J) % 128 + 1] endfor * Initialize the data that is required for the self-calibration. HomMatrices2D := [] Rows1 := [] Cols1 := [] Rows2 := [] Cols2 := [] NumMatches := [] for J := 0 to |From| - 1 by 1 * Select the images to match. select_obj (Images, ImageF, From[J]) select_obj (Images, ImageT, To[J]) * Perform the point extraction of the images. points_foerstner (ImageF, 1, 2, 3, 50, 0.1, 'gauss', 'true', RowsF, ColsF, CoRRJunctions, CoRCJunctions, CoCCJunctions, RowArea, ColumnArea, CoRRArea, CoRCArea, CoCCArea) points_foerstner (ImageT, 1, 2, 3, 50, 0.1, 'gauss', 'true', RowsT, ColsT, CoRRJunctions1, CoRCJunctions1, CoCCJunctions1, RowArea1, ColumnArea1, CoRRArea1, CoRCArea1, CoCCArea1) concat_obj (ImageT, ImageF, ImageTF) tile_images_offset (ImageTF, TiledImage, [0,0], [0,Width + 20], [-1,-1], [-1,-1], [-1,-1], [-1,-1], 2 * Width + 20, Height) gen_cross_contour_xld (PointsF, RowsF, ColsF + Width + 20, 6, rad(45)) gen_cross_contour_xld (PointsT, RowsT, ColsT, 6, rad(0)) * Convert the images to gray value images. rgb1_to_gray (ImageF, ImageFG) rgb1_to_gray (ImageT, ImageTG) * Determine the projective transformation between the images. proj_match_points_ransac (ImageFG, ImageTG, RowsF, ColsF, RowsT, ColsT, 'ncc', 10, 0, 0, 648, 968, [rad(-10),rad(40)], 0.5, 'gold_standard', 10, 42, HomMat2D, Points1, Points2) * After this, we accumulate the required data. HomMatrices2D := [HomMatrices2D,HomMat2D] Rows1 := [Rows1,subset(RowsF,Points1)] Cols1 := [Cols1,subset(ColsF,Points1)] Rows2 := [Rows2,subset(RowsT,Points2)] Cols2 := [Cols2,subset(ColsT,Points2)] NumMatches := [NumMatches,|Points1|] * The rest of the code within the loop visualizes the point matches. RF := subset(RowsF,Points1) CF := subset(ColsF,Points1) + Width + 20 RT := subset(RowsT,Points2) CT := subset(ColsT,Points2) gen_empty_obj (Matches) for K := 0 to |RF| - 1 by 1 gen_contour_polygon_xld (Match, [RF[K],RT[K]], [CF[K],CT[K]]) concat_obj (Matches, Match, Matches) endfor dev_clear_window () dev_display (TiledImage) dev_set_color ('blue') dev_display (Matches) dev_set_color ('green') dev_display (PointsF) dev_display (PointsT) dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Matches between images ' + From[J]$'d' + ' and ' + To[J]$'d') endfor dev_clear_window () dev_set_window_extents (-1, -1, 856, 428) dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Performing self-calibration...') * Perform the self-calibration. stationary_camera_self_calibration (128, 968, 648, 6, From, To, HomMatrices2D, Rows1, Cols1, Rows2, Cols2, NumMatches, 'gold_standard', ['focus','principal_point','kappa'], 'true', CameraMatrix, Kappa, RotationMatrices, X, Y, Z, Error) dev_clear_window () dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Removing radial distortions...') * Remove the radial distortions from the images. cam_mat_to_cam_par (CameraMatrix, Kappa, 968, 648, CamParam) change_radial_distortion_cam_par ('fixed', CamParam, 0, CamParOut) gen_radial_distortion_map (Map, CamParam, CamParOut, 'bilinear') map_image (Images, Map, Images) dev_clear_window () dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Adjusting the images radiometrically...') * Before we adjust the images radiometrically, we compute the perspective * transformations between the images from the camera matrix and the rotation * matrices that are returned by the self-calibration. They are more accurate * than the perspective transformations that are returned by the matching * since they have been optimized over all images. For details on how the * perspective transformation matrices are computed by the code below, see the * documentation of stationary_camera_self_calibration. hom_mat2d_invert (CameraMatrix, CameraMatrixInv) PermMat := [0.0,1.0,0.5,1.0,0.0,0.5,0.0,0.0,1.0] hom_mat2d_invert (PermMat, PermMatInv) hom_mat2d_compose (CameraMatrixInv, PermMatInv, CamMatPermInv) hom_mat2d_compose (PermMat, CameraMatrix, CamMatPerm) HomMats2D := [] for J := 0 to |From| - 1 by 1 RotMatFrom := RotationMatrices[9 * (From[J] - 1):9 * (From[J] - 1) + 8] RotMatTo := RotationMatrices[9 * (To[J] - 1):9 * (To[J] - 1) + 8] hom_mat2d_transpose (RotMatFrom, RotMatFromInv) hom_mat2d_compose (RotMatTo, RotMatFromInv, RotMat) hom_mat2d_compose (RotMat, CamMatPermInv, RotCamMatInv) hom_mat2d_compose (CamMatPerm, RotCamMatInv, HomMat2D) HomMats2D := [HomMats2D,HomMat2D] endfor * Now adjust the images radiometrically. Since the exposure and white balance * were set to automatic, we calculate 'mult_gray'. Since the camera is a consumer * camera and therefore has a highly nonlinear response, we compute 'response'. * To compensate the vignetting in the images, we compute 'vignetting'. Finally, * to speed up the optimization, we use a subsampling by a factor of 4. adjust_mosaic_images (Images, CorrectedImages, From, To, 118, HomMats2D, 'gold_standard', ['mult_gray','response','vignetting','subsampling_4'], 'laguerre') * Since the reference image was not aligned perfectly horizontally, we modify the * calibrated rotation matrices by rotating them by -5.5 degrees around the x axis. hom_mat3d_identity (HomMat3D) hom_mat3d_rotate (HomMat3D, rad(-5.5), 'x', 0, 0, 0, HomMat3D) RotMat := [HomMat3D[0:2],HomMat3D[4:6],HomMat3D[8:10]] RotMats := [] for J := 0 to 127 by 1 RotMatCalib := RotationMatrices[J * 9:J * 9 + 8] hom_mat2d_compose (RotMatCalib, RotMat, RotMatRot) RotMats := [RotMats,RotMatRot] endfor dev_clear_window () dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Creating spherical mosaic of the original images...') * Create the spherical mosaic of the original images. gen_spherical_mosaic (Images, SphericalMosaicOrig, CameraMatrix, RotMats, -90, 90, -180, 180, 0, 'voronoi', 'bilinear') get_image_size (SphericalMosaicOrig, Width, Height) dev_set_part (0, 0, Height - 1, Width - 1) dev_clear_window () dev_display (SphericalMosaicOrig) dev_set_color ('yellow') set_tposition (WindowHandle, Height - 300, 20) write_string (WindowHandle, 'Spherical mosaic of the original images') set_tposition (WindowHandle, Height - 150, 20) write_string (WindowHandle, 'Press \'Run\' to continue') stop () dev_clear_window () dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Creating spherical mosaic of the radiometrically adjusted images...') * Create the spherical mosaic of the radiometrically adjusted images. gen_spherical_mosaic (CorrectedImages, SphericalMosaicAdjust, CameraMatrix, RotMats, -90, 90, -180, 180, 0, 'voronoi', 'bilinear') get_image_size (SphericalMosaicAdjust, Width, Height) dev_set_part (0, 0, Height - 1, Width - 1) dev_clear_window () dev_display (SphericalMosaicAdjust) dev_set_color ('yellow') set_tposition (WindowHandle, Height - 300, 20) write_string (WindowHandle, 'Spherical mosaic of the radiometrically adjusted images') set_tposition (WindowHandle, Height - 150, 20) write_string (WindowHandle, 'Press \'Run\' to continue') stop () dev_clear_window () dev_set_color ('yellow') set_tposition (WindowHandle, 20, 20) write_string (WindowHandle, 'Creating blended spherical mosaic of the radiometrically adjusted images...') * Create the blended spherical mosaic of the radiometrically adjusted images. gen_spherical_mosaic (CorrectedImages, SphericalMosaicAdjustBlend, CameraMatrix, RotMats, -90, 90, -180, 180, 0, 'blend', 'bilinear') get_image_size (SphericalMosaicAdjustBlend, Width, Height) dev_set_part (0, 0, Height - 1, Width - 1) dev_clear_window () dev_display (SphericalMosaicAdjustBlend) dev_set_color ('yellow') set_tposition (WindowHandle, Height - 300, 20) write_string (WindowHandle, 'Blended spherical mosaic of the radiometrically adjusted images')
06-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值