球面上的映射图像

Mapping image on spherical surface

简而言之,我需要映射要在球面上使用的图像。我试图这样做几个小时。在 google 中搜索我没有找到任何合适的解决方案(为愚蠢的人解释)。

我认为此 link 中的代码: https://www.codeproject.com/articles/19712/mapping-images-on-spherical-surfaces-using-c 是我需要的。但是(我认为一切都很好)可以让它在 Julia 中工作。

到目前为止,这是我的代码:

image = brightNoise(height,width,seed,rand=true)

arr = Array{Float64}(height,width)

function MapCoordinate(i1, i2,w1,w2,p)
    return ((p - i1) / (i2 - i1)) * (w2 - w1) + w1
end

function Rotate(angle, axisA, axisB)
    return axisA * cos(angle) - axisB * sin(angle),axisA * sin(angle) + axisB * cos(angle)
end

phi0 = 0.0
phi1 = pi
theta0 = 0.0
theta1 = 2.0*pi
radius = 50


arr = Array{Float64}(height,width)

for i= 1:size(image)[1]
    for j= 1:size(image)[2]
        #map the angles from image coordinates
        theta = MapCoordinate(0.0,width - 1,theta1, theta0, i)
        phi = MapCoordinate(0.0,height - 1,phi0,phi1, j)
        #find the cartesian coordinates
        x = radius * sin(phi) * cos(theta);
        y = radius * sin(phi) * sin(theta);
        z = radius * cos(phi);
        #apply rotation around X and Y axis to reposition the sphere
        y,z=Rotate(1.5, y, z);
        x,z=Rotate(pi/2, x, z);
        #plot only positive points
        if (z > 0)
            color = image[i,j]
            ix = floor(Int64,x)  
            iy = floor(Int64,y)
            arr[ix,iy] = color
            println(ix,iy)
        end
     end
 end

image 只是 Julia 中产生的黑白噪声,我需要用它包裹一个球体。

我不太清楚您的代码在做什么,但修复一些索引问题可能会帮助您入门。无论如何,它看起来像是在做一些球形的事情...

using Images, FileIO
mandrill = load(mandrill.png")    
height, width = size(mandrill)
arr = colorim(Array{Float64}(height, width, 3))

function MapCoordinate(i1, i2, w1, w2, p)
    return ((p - i1) / (i2 - i1)) * (w2 - w1) + w1
end

function Rotate(angle, axisA, axisB)
    return axisA * cos(angle) - axisB * sin(angle),axisA * sin(angle) + axisB * cos(angle)
end

phi0 = 0.0
phi1 = pi
theta0 = 0.0
theta1 = 2.0 * pi
radius = 200

for i = 1:size(mandrill, 1)
    for j = 1:size(mandrill, 2)
        # map the angles from image coordinates
        theta = MapCoordinate(1.0, width - 1, theta1, theta0, i)
        phi   = MapCoordinate(1.0, height - 1,  phi0,   phi1, j)
        # find the cartesian coordinates
        x = radius * sin(phi) * cos(theta)
        y = radius * sin(phi) * sin(theta)
        z = radius * cos(phi)
        # apply rotation around X and Y axis to reposition the sphere
        y, z = Rotate(1.5, y, z)
        x, z = Rotate(pi/2, x, z)

        # plot only positive points
        if z > 0
            color = mandrill[i, j]
            ix = convert(Int, floor(x + width/2))
            iy = convert(Int, floor(y + height/2))
            arr[ix, iy, :] = [color.r, color.g, color.b]
        end
     end
 end

save("/tmp/mandrill-output.png", arr)
run(`open /tmp/mandrill-output.png`)