{"id":73,"date":"2012-02-14T21:14:24","date_gmt":"2012-02-15T02:14:24","guid":{"rendered":"https:\/\/peterabeles.com\/blog\/?p=73"},"modified":"2012-02-14T21:40:30","modified_gmt":"2012-02-15T02:40:30","slug":"inverse-radial-distortion-formula","status":"publish","type":"post","link":"https:\/\/peterabeles.com\/blog\/?p=73","title":{"rendered":"Inverse Radial Distortion Formula"},"content":{"rendered":"<h2>Where are the inverse equations hiding?<\/h2>\n<p>A common problem in computer vision is modelling lens distortion.\u00a0 Lens distortion distort the shape of objects and introduce large errors in structure from motion applications.\u00a0 Techniques and tools for calibrating cameras and removing lens distortion are widely available.\u00a0 While books and papers readily provide the forward distortion equations (given an ideal undistorted coordinate, compute the distorted coordinate) inverse equations are much harder to come by.<\/p>\n<p>Turns out there is no analytic equation for inverse radial distortion.\u00a0 Which might explain the mysterious absence of inverse equations, but still it would be nice if this issue was discussed in common references. First a brief summary of background equations is given, followed by the solution to the inverse distortion problem.<\/p>\n<p><strong>Inverse Distortion Problem:<\/strong> <em>Given a distorted image coordinate and distortion parameters, determined the coordinate of the ideal undistorted coordinate.<\/em><\/p>\n<h2>Background<\/h2>\n<p>Unlike the idealized pin-hole camera model, real world cameras have lens distortions.\u00a0 Radial distortion is a common model for lens distortion and is summarized by the following equations:<\/p>\n<table>\n<tbody>\n<tr>\n<td><img src='https:\/\/s0.wp.com\/latex.php?latex=%5Chat%7Bx%7D+%3D+x+%2B+x%5Bk_1+r%5E2+%2B+k_2+r%5E4%5D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='\\hat{x} = x + x[k_1 r^2 + k_2 r^4]' title='\\hat{x} = x + x[k_1 r^2 + k_2 r^4]' class='latex' \/><\/td>\n<\/tr>\n<tr>\n<td><img src='https:\/\/s0.wp.com\/latex.php?latex=%5Chat%7Bu%7D+%3D+u+%2B+%28u-u_0%29%5Bk_1+r%5E2+%2B+k_2+r%5E4%5D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='\\hat{u} = u + (u-u_0)[k_1 r^2 + k_2 r^4]' title='\\hat{u} = u + (u-u_0)[k_1 r^2 + k_2 r^4]' class='latex' \/><\/td>\n<\/tr>\n<tr>\n<td><img src='https:\/\/s0.wp.com\/latex.php?latex=r%5E2%3Du_x%5E2+%2B+u_y%5E2&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='r^2=u_x^2 + u_y^2' title='r^2=u_x^2 + u_y^2' class='latex' \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>where <img src='https:\/\/s0.wp.com\/latex.php?latex=%5Chat%7Bu%7D%3D%5B%5Chat%7Bu%7D_x%2C%5Chat%7Bu%7D_y%5D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='\\hat{u}=[\\hat{u}_x,\\hat{u}_y]' title='\\hat{u}=[\\hat{u}_x,\\hat{u}_y]' class='latex' \/> and <img src='https:\/\/s0.wp.com\/latex.php?latex=u&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='u' title='u' class='latex' \/> are the observed distorted and ideal undistorted pixel coordinates, <img src='https:\/\/s0.wp.com\/latex.php?latex=%5Chat%7Bx%7D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='\\hat{x}' title='\\hat{x}' class='latex' \/> and <img src='https:\/\/s0.wp.com\/latex.php?latex=x&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='x' title='x' class='latex' \/> are the observed and ideal undistorted normalized pixel coordinates, and <img src='https:\/\/s0.wp.com\/latex.php?latex=k_1%2C+k_2&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='k_1, k_2' title='k_1, k_2' class='latex' \/> are radial distortion coefficients.\u00a0 The relationship between normalized pixel and unnormalized pixel coordinates is determined by the camera calibration matrix, <img src='https:\/\/s0.wp.com\/latex.php?latex=u%3DC+x&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='u=C x' title='u=C x' class='latex' \/>, where <img src='https:\/\/s0.wp.com\/latex.php?latex=C&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='C' title='C' class='latex' \/> is the 3&#215;3 calibration matrix.<\/p>\n<h2>Solution<\/h2>\n<p>While there is no analytic solution there is an iterative solution.\u00a0 The iterative solution works by first estimating the radial distortion&#8217;s magnitude at the distorted point and then refining the estimate until it converges.<\/p>\n<ol>\n<li><img src='https:\/\/s0.wp.com\/latex.php?latex=x%3DC%5E%7B-1%7D%5Chat%7Bu%7D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='x=C^{-1}\\hat{u}' title='x=C^{-1}\\hat{u}' class='latex' \/><\/li>\n<li>do until converge:<\/li>\n<ol>\n<li><img src='https:\/\/s0.wp.com\/latex.php?latex=r%3D%7C%7Cx%7C%7C%5E2&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='r=||x||^2' title='r=||x||^2' class='latex' \/><\/li>\n<li><img src='https:\/\/s0.wp.com\/latex.php?latex=m%3Dk_1+r%5E2+%2B+k_2+r%5E4&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='m=k_1 r^2 + k_2 r^4' title='m=k_1 r^2 + k_2 r^4' class='latex' \/><\/li>\n<li><img src='https:\/\/s0.wp.com\/latex.php?latex=x%3D%5Cfrac%7BC%5E%7B-1%7D%5Chat%7Bu%7D%7D%7B1%2Bm%7D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='x=\\frac{C^{-1}\\hat{u}}{1+m}' title='x=\\frac{C^{-1}\\hat{u}}{1+m}' class='latex' \/><\/li>\n<\/ol>\n<li><img src='https:\/\/s0.wp.com\/latex.php?latex=u+%3D+%5Cfrac%7Bx%2Bx_0+m%7D%7B1%2Bm%7D&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='u = \\frac{x+x_0 m}{1+m}' title='u = \\frac{x+x_0 m}{1+m}' class='latex' \/><\/li>\n<\/ol>\n<p>Where <img src='https:\/\/s0.wp.com\/latex.php?latex=x_0&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='x_0' title='x_0' class='latex' \/> is the principle point\/image center, and <img src='https:\/\/s0.wp.com\/latex.php?latex=%7C%7Cx%7C%7C&#038;bg=f7f3ee&#038;fg=333333&#038;s=0' alt='||x||' title='||x||' class='latex' \/> is the Euclidean norm. Only a few iterations are required before convergence.\u00a0 For added speed when applying to an entire image the results can be cached.\u00a0 A similar solution can be found by adding in terms for tangential distortion.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Where are the inverse equations hiding? A common problem in computer vision is modelling lens distortion.\u00a0 Lens distortion distort the shape of objects and introduce large errors in structure from motion applications.\u00a0 Techniques and tools for calibrating cameras and removing lens distortion are widely available.\u00a0 While books and papers readily provide the forward distortion equations [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,12],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-calibration","category-computer-vision"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=73"}],"version-history":[{"count":11,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/73\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peterabeles.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}