繁体   English   中英

使用 imageR 将图像从笛卡尔坐标映射到极坐标

[英]Mapping image from cartesian to polar coordinates with imageR

我正在尝试使用 imageR 将全景图像映射到极坐标,但得到了奇怪的结果。

举个例子,我想用这样的方形全景图(由Flickr 用户 gadl ( Alexandre Duret-Lutz ) 在 CC BY-NC-SA 下提供并编辑成一个正方形):

方形全景

并将其重新映射为类似的内容(我在 GIMP 中已完成):

方形全景图的极坐标重映射

我已经非常接近 imageR 使用以下代码:

library(imager)
pano <- mirror(load.image("pano_image.jpg"), "y") # mirroring the image to map to center
map.shift <- function(x,y) list(x = y*cos(x), y = y*sin(x)) # Here, y is the radius and x is theta
polar_pano <- imwarp(pano, map = map.shift)
plot(polar_pano)

但我得到了奇怪的结果:

极坐标映射全景的成像器输出

我不确定为什么它只映射到一个象限? (注意:我意识到在这个例子中插值会很奇怪——这不是问题)。 为了确认这应该有效,这是一个玩具示例:

library(ggplot)
test <- data.frame("val" = rep(100:1, each = 99), theta = rep(1:100, 99), r = rep(1:100, each = 99))
ggplot(test, aes(x = theta, y = r, col = val)) + geom_point()

# Now converting from polar to cartesian
test$x <- test$r*cos(test$theta)
test$y <- test$r*sin(teast$theta)
ggplot(test_p2c, aes(x = x, y = y, col = val)) + geom_point()

您的结果只有一个象限,因为生成的转换既有负值也有正值。

在您的函数中,结果的左上角是(-400, -400) ,右下角是(400, 400) 减半并加上 200 使其成为(0, 0)(400, 400)

缩放触发参数以从-pipi

为了使原始图像的底部成为结果圆的中心, x需要是三角函数内部的变量。

library(imager)

pano <- load.image("pano_image.jpg")
pano <- mirror(load.image("pano_image.jpg"), "y")

map_shift <- function(x, y) {
  list(
    x = y * cos((x - 200) / 400 * 2 * pi) / 2 + 200,
    y = y * sin((x - 200) / 400 * 2 * pi) / 2 + 200
  )
}

polar_pano <- imwarp(pano, map = map_shift)
plot(polar_pano)

阴谋

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM