角度に問題があります。atan
は、角度をラジアンで返します。 あなたはそれを丸める場合は、左の多くの情報がありません...
はして試してみてください。
a = atan(y0/x0) * 215/(pi/2)
それは、明らかに逆変換である、あなたが期待するイメージではありません 画像の中央に中心を置きます。
# Load the image
library(png)
library(RCurl)
d <- readPNG(getBinaryURL("http://i.stack.imgur.com/rMR3C.png"))
image(d, col=gray(0:255/255))
# Origin for the polar coordinates
x0 <- ncol(d)/2
y0 <- nrow(d)/2
# The value of pixel (i,j) in the final image
# comes from the pixel, in the original image,
# with polar coordinates (r[i],theta[i]).
# We need a grid for the values of r and theta.
r <- 1:ceiling(sqrt(max(x0,nrow(d))^2 + max(y0,ncol(d))^2))
theta <- -pi/2 + seq(0,2*pi, length = 200)
r_theta <- expand.grid(r=r, theta=theta)
# Convert those polar coordinates to cartesian coordinates:
x <- with(r_theta, x0 + r * cos(theta))
y <- with(r_theta, y0 + r * sin(theta))
# Truncate them
x <- pmin(pmax(x, 1), ncol(d))
y <- pmin(pmax(y, 1), nrow(d))
# Build an empty matrix with the desired size and populate it
r <- matrix(NA, nrow=length(r), ncol=length(theta))
r[] <- d[cbind(x,y)]
image(r, col=gray(0:255/255))
ありがとう、素晴らしい答え!おそらくコードの各部分が何をしているのか説明できますか?私はあなたがrとthetaとsin/cos値の乗算に使用している数式について少し混乱しています。もう一度ありがとう – by0
私は少しコードを簡略化し、いくつかのコメントを追加しました。 –