# ImageForwardTransformation produces strange artifacts

I am trying to manipulate an image in equirectangular projection with ImageForwardTransformation. I want to change the projection's inclination to the ecliptic. For this, I created a transformation function

changeEcliptic =
Compile[{{θφ, _Real, 1}, {rpy, _Real, 1}},
With[{θ = θφ[[2]], φ = θφ[[1]], roll = rpy[[1]], pitch = rpy[[2]], yaw = rpy[[3]]},
{
ArcTan[
Cos[θ] Sin[pitch] + Cos[pitch] Cos[roll + φ] Sin[θ],
-Cos[pitch] Cos[θ] Sin[yaw] + Sin[θ] (Cos[roll + φ] Sin[pitch] Sin[yaw] +
Cos[yaw] Sin[roll + φ])
],
ArcTan[
Cos[pitch] Cos[yaw] Cos[θ] + Sin[θ] (-Cos[yaw] Cos[roll + φ]
Sin[pitch] + Sin[yaw] Sin[roll + φ]),
Sqrt[(Cos[θ] Sin[pitch] + Cos[pitch] Cos[roll + φ] Sin[θ])^2 +
(Cos[pitch] Cos[θ] Sin[yaw] - Sin[θ] (Cos[roll + φ] Sin[pitch] Sin[yaw] +
Cos[yaw] Sin[roll + φ]))^2]
]
}
],
CompilationTarget -> "C", RuntimeOptions -> "Speed"
]


which I derived from

CoordinateTransform["Cartesian" -> "Spherical",
RollPitchYawMatrix[{roll, pitch, yaw}].# &@
CoordinateTransform["Spherical" -> "Cartesian", {r, θ, φ}]]


I then import my image

mwpic = Import["https://upload.wikimedia.org/wikipedia/commons/thumb/a/a1/ESO_-_The_Milky_Way_panorama_%28by%29.jpg/640px-ESO_-_The_Milky_Way_panorama_%28by%29.jpg"]


And apply the transformation:

ImageForwardTransformation[mwpic,
changeEcliptic[##, {0 Degree, -40 Degree, 0 Degree}] &,
640, Background -> Green,
PlotRange -> {{-π, π}, {0, π}}, DataRange -> {{-π, π}, {0, π}}
]


The transformed image has a strange black band at the bottom which should not be there. How to achieve a proper transformation of an equirectangular image with roll, pitch and yaw? Is this a bug of ImageForwardTransformation?

UPDATE

ImageTransformation seems to work fine (the angle has to be reversed). Looks like a bug to me.

It seems like a nuisance coming from the interpolation used by ImageForwardTransformation when you use negative values of rpy[[2]]. The image looks grainy but overall OK without interpolation:

gr = ImageForwardTransformation[mwpic,
changeEcliptic[##, {0 Degree, -40 Degree, 00 Degree}] &, 640,
PlotRange -> {{-π, π}, {0, π}},
DataRange -> {{-π, π}, {0, π}}, "Interpolated" -> False]


You may perform an "after the fact" interpolation (not with precise results, of course):

Inpaint[gr, ColorNegate@Binarize[gr, .0001], Method -> "TotalVariation"]


But since your scheme works OK with positive values of rpy[[2]] you may (better) do:

ImageReflect@
ImageForwardTransformation[ImageReflect@mwpic,
changeEcliptic[##, {0 Degree, 40 Degree, 0 Degree}] &, 640,
PlotRange -> {{-π, π}, {0, π}},
DataRange -> {{-π, π}, {0, π}}]