Using ImageTransformation to implement relativistic aberration effect

****The desired effect should be images that look like something out of Star Wars like when you are boosting to high speeds in the Millennium Falcon.****

This problem was tackled by Daniel Weiskopf in his paper An Image-Based Approach to Special Relativistic Rendering the useful maths background is on page 2-4 where the "aberration effect stuff" is on page 4 and with the generated images being on page 5.

• I basically want to be able to create the exact same resulting images by using mathematica as the programming language instead.
• I am certain that the way to do this is using the ImageTransformation command and would thus like to put this aberration equation correctly into the command to get the same image deformations.

To summarise the main information I think is needed:

The relativistic aberration equation is an equation which shows the distortion to geometry occurred by traveling at relativistic (speed close to speed of light).This is a consequence of special relativity. This "geometric change" is given as an angular equation which relates an angle in the moving observers frame relative to an observer at rest. Apologies I am still getting used to using this so not entirely sure how I can show you but I can explain. Since this geometric effect is given by an equation I basically tried using ImageTransformation to transform an image using the aberration equation as the "function"

The relativistic aberration equation can be cast as:

$$\cos \theta_{obs} = \frac{\cos \theta_{src} - \frac{v}{c}}{1 - \frac{v}{c} \cos\theta_{src}}$$

Or in Mathematica code:

aberrationTheta[q_, s_] :=
ArcCos[(Cos[q] - s)/(1 - (s) Cos[q])]


where s is a fraction of the speed of light.

The steps which I was trying to do to get this effect working (to no avail) were:

1. Somehow define some spherical coordinates for the image $$(\theta^{\prime}, \phi^{\prime})$$ where the prime denotes we are in the observers frame and non prime which would be the object (image) frame. Also making sure the origin of the coordinate system is in located in the center of every input image rather than at a vertex of an image to allow for the deformation effect to fully work. The reasons for these "different frames" is we can imagine ourselves travelling at high speed (boosting) into the image and thus a reference frame allows us to see these effects in the eyes of us actually moving but also the image itself. These transformations are effectively allowing us to "transform" between the 2 reference frames (ours and the image).

2. Each pixel in the image is given a coordinate in our system, these individual "pixel" coordinates are then transformed by the aberration effect. Since the ImageTransformation command only allows individual pixels of the image to be transformed in cartesian format $$(x,y) ->(x^{'},y^{'})$$ where x,y represent cartesian coordinates. I tried to express the aberration effect by some cartesian coordinate transform to these spherical coordinates: $$x=\theta\cos{\phi}$$ and $$y=\theta\sin{\phi}$$ are the original and after transformation we have $$x^{'}=\theta^{'}\cos{\phi}$$ and $$y^{'}=\theta^{'}\sin{\phi}$$ where the prime denotes in "transformed reference frame". The $$\phi$$ is the angle from the x-axis (range $$0-2\pi$$) and $$\theta$$ is the angle from the z-axis ($$0-\pi$$) (since an image is 2-d we can define the y coordinate as being up and down and the x being right and left and the positive z being "into the image").

3. Once this is done we can somehow plug these transformations in (not too sure how) along with some image (Any 2D image) into the ImageTransformation[] command and get some output as to what the "new" deformed image looks like.

Note: My main aim is just to get a general code so that I can play around with arbitrary values for say $$\beta$$ the fraction of the speed of light to see what the effect would be at different speeds.

Would appreciate someone showing code for how this can be done in the most efficient manner using ImageTransformation with the function which does the transforming being the relativistic aberration equation to produce output images of this geometric deformation.

• Could you give us some background? What is a relativistic aberration equation? What has your approach been thus far and why is it not possible to find in the docs? Dec 12, 2018 at 19:37
• Hi sure. The relativistic aberration equation is an equation which shows the changes to geometry occurred by traveling at relativistic (speed close to speed of light). This "geometric change" is given as an angular equation which relates an angle in the moving observers frame relative to an observer at rest. Apologies I am still getting used to using this so not entirely sure how I can show you but I can explain. Since this geometric effect is given by an equation I basically tried using the "ImageTransformation" command to transform an image using the aberration equation as the "function". Dec 12, 2018 at 19:50
• Put that in the question body. Also show sample sample code and equations people will need. In general the idea is to minimize the work that someone who codes well in Mathematica but doesn't know about your specific field has to do. By making this really easy for others you maximize the chances your question gets answered. Dec 12, 2018 at 19:52
• Ok thank you will do, I am suprised by the speed of responses. How to I type equations? Does it use Tex? @b3m2a1 Dec 12, 2018 at 19:56
• I'd use TeX for pure math and use command-k/control-k to format code (select and press that). You can look up the help on Markdown formatting for more. Dec 12, 2018 at 20:22

Update 2

To get the images in the linked paper you need much more than what you have given us. We actually need full 3D data, as we need proper spherical coordinates. Their setup has that. An arbitrary 2D image does not... Note too that the authors' Figure 3 could never has come from Figure 2 as it has features that don't appear in Figure 2 and instead require a full 3D coordinate set for the scene.

On the other hand, I did realize I could update my aberration function to be centered arbitrarily on the image:

aberrate // Clear
aberrate[img_, s_, center_: {.5, .5}] :=
ImageTransformation[
img,
With[
{c = # - center},
{cosJ = c[[1]]/Norm[c]},
{q = c[[1]]/cosJ, j = ArcTan[c[[1]], c[[2]]]},
{qobs = ArcCos[(Cos[q] - s)/(1 - (s) Cos[q])]},
qobs*{cosJ, Sin@j} + center
] &,
DataRange -> {{0, 1}, {0, 1}},
]


And this shows much more interesting aberrations:

aberrate[img, .5, {0, 0}]


Update

Here's what we get based off your explanation:

aberrate[img_, s_] :=
ImageTransformation[
img,
With[
{c = # - {.5, .5}},
{cosJ = c[[1]]/Norm[c]},
{q = c[[1]]/cosJ, j = ArcTan[c[[1]], c[[2]]]},
{qobs = ArcCos[(Cos[q] - s)/(1 - (s) Cos[q])]},
qobs*{cosJ, Sin@j} + {.5, .5}
] &,
DataRange -> {{0, 1}, {0, 1}},
]


Here's an animation:

It's honestly pretty boring. Here's a constellation of images stitched together at different relative speeds:

Low key still boring though. If we included perspective effects we'd probably get a cooler result, but I don't have any math to implement for that and don't want to research.

Original

So I decided to break my own rules and did more reading for this than intended, but here's my best guess at what you want:

aberrationTheta[q_, s_] := ArcCos[(Cos[q] - s)/(1 - (s) Cos[q])];
aberrationScaling[q_, s_] :=
ScalingMatrix[1 - aberrationTheta[q, s]/π, {-1, 1}]
img = ImageResize[ExampleData[{"TestImage", "Mandrill"}], {250, 250}]


Then we'll use ImagePerspectiveTransformation to provide some kind of compression as I think that's the idea here but I really don't know, as I know nothing about this topic:

ImagePerspectiveTransformation[img, aberrationScaling[π/10, .99]]


• First and foremost thank you and I understand you don't know much about this topic not sure if there is a system of getting this question noticed more by people who are more familiar. This is not the exact thing I was trying to do, not sure if it would help if I can link some academic papers which show what final images look like. The main divergence from what I was looking for and your solution is when you tried providing a "compression" I don't think this gives the full effect. What I wanted isn't just a "linear compression" but an actual change in each pixel by the aberration equation. Dec 12, 2018 at 21:51
• @user61882 Yeah link them in your question body. We can all read academic papers (if we can get through the paywall). You'll need to be more precise about what you mean by "actual change in each pixel" because the equation I found on Wikipedia gives an equation in terms of $\theta$ and $v/c$ which have no obvious correspondence with pixels. Dec 12, 2018 at 22:49
• Sure, also you know you said I need to give more date ie "3D data" would you happen to know what exactly I need to specify? I dont mind if you implement some arbitrary data and then see what results would come of it? Dec 13, 2018 at 11:45