R中的图像极坐标变换

Image polar transformation in R

我有一张这样的照片,用 Google 街景应用拍摄并裁剪到上半部分:

我用Gimp polar coordinates filter to obtain this new image:

我想在 R 中做同样的事情,保留所有像素值信息。

Here我发现了一个类似的问题,但结果并不完全是我需要的(转换的中心是一个角)。调整后的代码(弧度有问题)是:

# Load the image
library(png)
library(RCurl)
d <- readPNG( getBinaryURL( "http://i.stack.imgur.com/rMR3C.png" ) )
image(d)

x0 = as.vector(col(d))
y0 = as.vector(row(d))

r = sqrt( (x0^2) + (y0^2)  ) #x
a = atan(y0/x0) * 215 / (pi/2) #y
m = as.matrix(data.frame(y=a, x=r))

m = round(m)
m[m>215] = NA
m[m==0] = NA

xn = d[m]
xn = matrix(xn, 215, 215)

image(xn)

该问题的答案对问题进行了扩展,并显示了进行极坐标到笛卡尔变换的代码,但我无法进行相反的操作。

magick 包可以完成这项工作。

library(magick)

# load sample image
z <- image_read("https://i.stack.imgur.com/MYIeg.jpg")
 
# do polar distortion
zp <- image_distort(z, # source image
                    "Polar", # type, check availability at distort_types()
                    c(0), # coordinates, I could not understand fully but this work
                    bestfit=T # crop to the image to a square
)

plot(zp)