我用这个问题来帮助我想出一个不失真的图像协调系统。现在,我不确定如何在图像中实现新的坐标系,以便能够生成不失真的图像。
我在使用 R 时无法找到不涉及 Matlab、OpenCV 或C++ 的答案。
我从引用的问题中使用的答案给了我以下转换后的 xy 坐标:
1 -19.50255239, -19.50255239
2 -18.26735544, -18.26735544
3 -17.03391152, -17.03391152
4 -15.80221494, -15.80221494
5 -14.57225998, -14.57225998
6 -13.34404095, -13.34404095
...
以此类推,512 x 512 图像中的 512 像素。
如何将此应用回原始的 512 x 512 图像是我正在努力解决的问题。我在此处的 Open CV 页面和特定的预定义 shifts或latitudinal /longitudinal shifts等页面上看到了一些提及,使用SpatialObjectsDataFrame s,但不是从一个用户定义的 xy 坐标列表到另一个。
- 获取源图像坐标的示例:
im_coords <- RSAGA::grid.to.xyz(as.matrix(as.raster(im)))
(注意,我实际上并不想对图像进行光栅化,这正是我当时发现的)
- 我用来获取转换后坐标的代码:
undistort <- function(X, Y, a, b, c, d = 1, imWidth = 512, imHeight = 512) {
#radial barrel distortion
normX <- X - (imWidth / 2)
normY <- Y - (imHeight / 2)
#rmax
radius_u <- sqrt(imWidth^2 + imHeight^2)
#normalize r so that its between 0 and 1
r <- sqrt(normX^2 + normY^2) / radius_u
#Barrel distorition equation: where "r" is the destination radius and "Rsrc" is the source pixel to get the pixel color from
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))
}
这是一个示例样本 512x512 .png 桶形扭曲图像:https ://imgur.com/a/W9Qz70W
我想知道克里金法是否有用?还是gdalwarp或proj4string?不知道如何实现这些。
更新:使用 Rohit 的建议,我能够从以下位置扭曲彩虹网格:
对此:
当我用桶形图像尝试它时,我得到了这个奇怪的叠加图像:
好的,我认为这取决于您使用的系数,如下所示: