簡體   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