Correcting barrel lens distortion in an x,y series in R

对着背影说爱祢 提交于 2019-12-01 12:48:08

I've got a somewhat satisfactory solution by modifying the function provided in the question, using the ImageMagick distortion algorithm:

Rsrc = r * ( Ar^3 + Br^2 + C*r + D )

Like so:

undistortFun <- function(x, y, a, b, c, d = 1, imWidth = 640, imHeight = 480) {

    normX <- X - (imWidth / 2)
    normY <- Y - (imHeight / 2)

    radius_u <- sqrt(imWidth^2 + imHeight^2)

    r <- sqrt(normX^2 + normY^2) /  radius_u

    Rsrc <- r * (a*r^3 + b*r^2 + c*r + d)

    theta <- ifelse(Rsrc == 0, 1, 1 / atan(Rsrc) * Rsrc)

    newX <- (imWidth / 2) + theta * normX
    newY <- (imHeight / 2) + theta * normY

    return(data.frame(X = newX, Y = newY))
}

Although I'm uncertain about the calculation of theta, and specifying zero distortion (a=0, b=0, c=0) still leads to a transformation. Nevertheless, it appears to do what I wanted in these samples:

Plot of original x,y data:

Plot of adjusted x,y data (where: a =0, b= -0.02, c = 0):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!