【问题标题】:Image polar transformation in RR中的图像极坐标变换
【发布时间】:2022-01-19 14:59:01
【问题描述】:

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

我使用Gimp polar coordinates filter 来获取这个新图像:

我想在 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)

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

【问题讨论】:

    标签: r image-processing polar-coordinates


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多