ECE661 Computer Vision HW 3 Rih-Teng Wu Email: [email protected] 1. Remove Projective Distortion โ Point to Point Correspondence When we see the parallel lines in the world plane are not parallel in an image, there exists the projective distortion in the image. To remove the projective distortion, we can use the homography calculated by means of point to point correspondence. According to what we have learned from HW2, the mapping between an image plane and a world plane is given by: ๐๐๐๐ = ๐ป๐ป๐๐๐ค๐ค Where ๐๐๐๐ is the points of image plane in homogeneous coordinates, ๐๐๐ค๐ค is the points of world plane in homogeneous coordinates, and ๐ป๐ป is the homography matrix. h11 x xโฒ Now, let ๐๐๐๐ = ๏ฟฝyโฒ๏ฟฝ , ๐๐๐ค๐ค = ๏ฟฝy๏ฟฝ, and ๐ป๐ป = ๏ฟฝh21 1 h31 1 h12 h22 h32 h13 h23 ๏ฟฝ. Since we only care about ratios h33 in homogeneous representation, the value of h33 can be set to 1. To solve the eight unknowns, we need to find at least four pairs of corresponding points in the image plane and the world plane. As a result, if now we have ๐๐ pairs of corresponding points, and denote the ๐๐ ๐ก๐กโ pair of corresponding points as (xi โฒ , yi โฒ ), (xi , yi ) , we have the following relation: xi โฒ = xi h11 + yi h12 + h13 โ xi โฒ xi h31 โ xi โฒ yi h32 yi โฒ = xi h21 + yi h22 + h23 โ yi โฒ xi h31 โ yi โฒ yi h32 Rewrite the above relation in matrix form, we have: x โก 1 โข0 โข โขxn โฃ0 y1 1 0 0 โฎ yn 1 0 0 0 x1 0 xn 0 y1 โฎ 0 yn h11 โกh โค โข 12 โฅ x1 โฒ 0 โx1 โฒ x1 โx1 โฒ y1 h โค โก โค 13 โข โฅ 1 โy1 โฒ x1 โy1 โฒ y1 y1 โฒ โฅ โฅ h โข × โข 21 โฅ =โข โฎ โฅ โฎ โฅ โฒ โฒ โฒ โขh22 โฅ 0 โxn xn โxn yn โฅ โขxn โฅ h 23 1 โyn โฒ xn โyn โฒ yn โฆ2nx8 โข โฅ โฃyn โฒ โฆ2nx1 h โข 31 โฅ โฃh32 โฆ8x1 Denote the above equation as ๐ด๐ดโ = ๐ต๐ต, then โ can be solved using the least square estimate method just in case we have more than four pairs of corresponding points. โ = (๐ด๐ด๐๐ ๐ด๐ด)โ1 ๐ด๐ด๐๐ ๐ต๐ต Once โ is found, we can use the homography matrix ๐ป๐ป to perform the mapping we desire. Some note for programming: a. In this task, the homography matrix ๐ป๐ป is calculated using ๐๐๐ค๐ค = ๐ป๐ป๐๐๐๐ . b. The information of world coordinates is given in unit of centimeter. Thus, I assume one pixel is equal to one centimeter. c. Using four corresponding point pairs, the homography ๐ป๐ป is solved. d. Similar to what we have done in HW2, at first the four corner points of image is mapped to the world plane using homography ๐ป๐ป, then the dimension of the output image is determined using the mapped points. Finally, the points in the output image are mapped back to the image using ๐ป๐ปโ1 to find the corresponding pixel values. 2. Remove Projective Distortion โ Vanishing Line Another way to remove the projective distortion is to use the vanishing lines in the image. Since an affine homography maps ๐๐โ to ๐๐โ , all we have to do is to find a homography that maps the vanishing line back to ๐๐โ . Suppose now we have two line pairs (๐ฟ๐ฟ1 โฒ, ๐ฟ๐ฟ2 โฒ) and (๐๐1โฒ , ๐๐2 โฒ) in the image that are supposed to be two parallel line pairs in the world plane (๐ฟ๐ฟ1 //๐ฟ๐ฟ2 , ๐๐1 //๐๐2 ) , we can find the intersection of this two line pairs, which are called vanishing points: ๐๐1 = ๐ฟ๐ฟ1 โฒ × ๐ฟ๐ฟ2 โฒ ๐๐2 = ๐๐1 โฒ × ๐๐2 โฒ Then, the vanishing line ๐ฟ๐ฟโฒ is given by: ๐ฟ๐ฟโฒ = ๐๐1 × ๐๐2 Therefore, if the vanishing line ๐ฟ๐ฟโฒ = [๐๐1 the vanishing line back to ๐๐โ is given by: ๐๐2 ๐๐3 ]T , the homography that maps 1 ๐ป๐ป๐๐ = ๏ฟฝ 0 ๐๐1 0 1 ๐๐2 0 0๏ฟฝ ๐๐3 As a result, apply this homography to our image can get rid of the projective distortion. Some note for programming: a. The homography is given by ๐๐๐ค๐ค = ๐ป๐ปp ๐๐๐๐ . Be careful to the mapping direction. b. The vanishing line needs to be normalized before putting into ๐ป๐ป๐๐ . c. The homography ๐ป๐ป๐๐ can be easily obtained using the vanishing line. d. Similar to what we have done befroe, at first the four corner points of image is mapped to the world plane using homography ๐ป๐ป๐๐ , then the dimension of the output image is determined using the mapped points. Finally, the points in the output image are mapped back to the image using ๐ป๐ป๐๐ โ1 to find the corresponding pixel values. 3. Remove Affine Distortion When we see the angles are not preserved in the image, there exists the affine distortion in the image. Suppose now we have two orthogonal lines L = [๐๐1 ๐๐2 ๐๐3 ]T and M = [๐๐1 ๐๐2 ๐๐3 ]T in the world plane, the angle between this two lines is given by: โ 1 0 0 LT Cโ M โ cos ฮธ = , Cโ = ๏ฟฝ0 1 0๏ฟฝ โ L)(M T C โ M) ๏ฟฝ(LT Cโ โ 0 0 0 Suppose now there is a homography ๐ป๐ป applied to the world plane and result in an image plane, the relation between the transformed lines and the original lines is given by L = ๐ป๐ป๐๐ ๐ฟ๐ฟโฒ , M = ๐ป๐ป๐๐ ๐๐โฒ . In addition, the transformed conic is given by โโฒ โ ๐ถ๐ถโ = H๐ถ๐ถโ H . Since cos ฮธ = 0 for two orthogonal lines in the world plane, we have: โ T โฒ LโฒT Ha Cโ Ha M = 0 A 0 ๏ฟฝ is the homography that can remove the affine distortion. 0 1 Expand the above equation we get: Where Ha = ๏ฟฝ T [๐๐1 โฒ ๐๐2 โฒ ๐๐3 โฒ] ๏ฟฝAA 0 ๐ ๐ 11 Denote S= AAT =๏ฟฝ๐ ๐ 12 ๐ ๐ 12 ๐ ๐ 22 ๏ฟฝ , we have: ๐๐1 โฒ 0๏ฟฝ ๏ฟฝ๐๐ โฒ๏ฟฝ = 0 2 0 ๐๐3 โฒ ๐ ๐ 11 ๐๐1 โฒ๐๐1 โฒ + ๐ ๐ 12 (๐๐1 โฒ๐๐2 โฒ+๐๐2 โฒ๐๐1 โฒ) + ๐ ๐ 22 ๐๐2 โฒ๐๐2 โฒ = 0 Since we only care about ratios, we can set ๐ ๐ 22 = 1 . As a result, we would need two orthogonal line pairs to solve for S. Once we have S, we can take the singular value decomposition (SVD) on S to get A : S = AAT = VD2 V T , A = VDV T Some note for programming: a. The homography now is given by ๐๐๐๐ = ๐ป๐ปa ๐๐๐ค๐ค . Be careful to the mapping direction. b. When selecting the points to find the homography ๐ป๐ปa , the coordinates of these points should correspond to the image plane where the projective distortion is removed. c. The MATLAB eig function could output negative eigenvalues, we should use the SVD to get A. d. To remove the projective distortion and the affine distortion, at first the four corner points of the original image is mapped to the world plane using homography ๐ป๐ปa โ1 ๐ป๐ป๐๐ , then the dimension of the output image is determined using the mapped points. Finally, the points in the output image are mapped back to the image using the inverse of ๐ป๐ปa โ1 ๐ป๐ป๐๐ to find the corresponding pixel values. e. Poor selection of points could lead to bad results. Select the points carefully. 4. One-Step Method To remove the projective distortion and the affine distortion at one step, we need to find a general homography: A H=๏ฟฝ T v 0 ๏ฟฝ 1 Since the dual conic in the image plane is given by: โโฒ Cโ = โ T HCโ H T = ๏ฟฝ AA v T AT a b/2 Av ๏ฟฝ=๏ฟฝb/2 c vTv d/2 e/2 d/2 e/2 ๏ฟฝ f When there are two lines in the image plane ๐ฟ๐ฟโฒ = [๐๐1 โฒ ๐๐2 โฒ ๐๐3 โฒ] and ๐๐โฒ = [๐๐1 โฒ ๐๐2 โฒ ๐๐3 โฒ] that is orthogonal to each other in the world plane, we have: โโฒ LโฒT Cโ a b/2 d/2 T c e/2 ๏ฟฝ [๐๐1 โฒ ๐๐2 โฒ ๐๐3 โฒ] M = 0 = [๐๐1 โฒ ๐๐2 โฒ ๐๐3 โฒ] ๏ฟฝb/2 d/2 e/2 f โฒ Since we only care about the ratios, we set f = 1. Therefore, we need five orthogonal line pairs to solve for five unknowns. Once the unknowns are solved, we a b/2 can again do SVD on S = AAT = ๏ฟฝ ๏ฟฝ to get A matrix, and then solve for b/2 c matrix v using v T AT =[d/2 e/2]. By doing this, we get the general homography that can get rid of the projective distortion and affine distortion. Some note for programming: a. The homography now is given by ๐๐๐๐ = H๐๐๐ค๐ค . Be careful to the mapping direction. b. When calculating the orthogonal line pairs, normalize these lines before solving for H. a b/2 d/2 c e/2 ๏ฟฝ is solved, normalize it before applying c. When the matrix ๏ฟฝb/2 d/2 e/2 f singular value decomposition. d. To remove the projective distortion and the affine distortion, at first the four corner points of the original image is mapped to the world plane using homography H โ1 , then the dimension of the output image is determined using the mapped points. Finally, the points in the output image are mapped back to the image using H to find the corresponding pixel values. e. It is possible that the dimension of output image is too large or too small. Thus, scale the dimension of the output image according to the original image size before finding the corresponding pixel values. f. Poor selection of points could lead to bad results. Select the points carefully. 5. Comment Although the two-steps method seems to be more complicated than the one-step method, it appears to me that the two-step method is more robust than the one-step method. First of all, although the two-step method requires more coding lines, it is more straightforward in concept than the one-step method. Second, when selecting the points to calculate the homography, the one-step method is very sensitive to the points being selected, which means it requires longer time to find the correct points to yield reasonable results. Therefore, I would say the two-steps method is more practical than the one-step approach when we try to remove the projective and affine distortion. 6. Results: Two-steps Image a โ original (green: point to point correspondence; red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.) Remove projective (point to point correspondence): Remove affine: Remove projective (vanishing line): Remove affine: Image b - original (green: point to point correspondence; red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.) Remove projective (point to point correspondence): Remove affine: Remove projective (vanishing line): Remove affine: Image c - original (green: point to point correspondence; red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.) Remove projective (point to point correspondence): Remove affine: Remove projective (vanishing line): Remove affine: 7. Results: One-step Image a - Original (five orthogonal line pairs, red: PQ-PR, PR-RS, RS-SQ, SQ-QP; yellow: PQ-PR) Remove projective and affine: Image b โ Original (five orthogonal line pairs, red: PQ-PR, PR-RS, RS-SQ, SQ-QP; yellow: PR-RS) Remove projective and affine: Image c โ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP, RP-PQ; yellow: PS-QR) Remove projective and affine: 8. Results: My Own Images (Two-Steps) Image a โ Original (red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.) Remove projective (vanishing line): Remove affine: Image b โ Original (red: parallel lines for vanishing line; yellow: two orthogonal line pairs PQ-QS and PS-QR for removing affine.) Remove projective (vanishing line): Remove affine: 9. Results: My Own Images (One-Step) Image a โ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP; yellow: PQ-QS, PS-QR) Remove projective and affine: Image b โ Original (five orthogonal line pairs, red: PQ-QS, QS-SR, SR-RP; yellow: PQ-QS, PS-QR) Remove projective and affine:
© Copyright 2026 Paperzz