Radial distortion - from screenshot to map

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
wollomat
Posts: 4
Joined: 2016-10-22T02:47:36-07:00
Authentication code: 1151

Radial distortion - from screenshot to map

Post by wollomat »

Hi everybody!

I currently create a map for a video game. I don't have access to a rendered map from the levelmesh, so I flew high above the map and took a screenshot. In the game, an arrow indicates, where the player currently is. The position is taken from the coordinates in the mesh, and thus only correct directly below the point, where I took the screenshot. I am now looking for a distortion method, that can reverse this (radial) distortion that results from taking a screenshot, instead of an orthogonal map.

So far, I have some pairs of source-pixel Xs,Ys from the image and the corresponding "Real" Coordinates Xd,Yd and the origin Ox,Oy which is not distorted. I neglect the Z coordinate, which will give wrong results, but I hope, that the impact is relatively small.

I tried "-distort Barrel" and computet with 4 Coordinate-Pairs and the Origin the parameters A,B,C,D via the set of linear equations, I get when using the Rsource=Rdest^4*A+Rdest^3*B+Rdest^2*C+Rdest*D. A,B and C look quite reasonable, but D is -169, which distorts the image a lot. Furthermore I tried to use "-distort Polynomial" with 9 coordinate-pairs, which also distorts the image beyond what is reasonable. Generally I thought this should be a rather simple thing, since the distortion is a radial one, stronger the further I am away from the origin. Which should be a thing for linear regression with some coordinate pairs.

I appreciate your help!
Wolle
Last edited by wollomat on 2016-10-22T04:24:07-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Radial distortion - from screenshot to map

Post by snibgo »

If you fly above a plane map, the only distortion I would expect is perspective. If the map is a significant proportion of a spherical world, that would be different.

Can you show some pictures that illustrate the distortion?
snibgo's IM pages: im.snibgo.com
wollomat
Posts: 4
Joined: 2016-10-22T02:47:36-07:00
Authentication code: 1151

Re: Radial distortion - from screenshot to map

Post by wollomat »

Here's the map, an x marks the origin.
You might be right, and what I mean by radial distortion is an effect of the perspective. Maybe I have to try again with some more points, to avoid artefacts.

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Radial distortion - from screenshot to map

Post by snibgo »

That image says nothing about the nature of the distortion. I'm not sure what you mean by "radial distortion".

If you have 3 (or more) points in the image, with the desired coordinates of each, put those 12 (or more) numbers in "-distort perspective". That might give the result you want.
snibgo's IM pages: im.snibgo.com
wollomat
Posts: 4
Joined: 2016-10-22T02:47:36-07:00
Authentication code: 1151

Re: Radial distortion - from screenshot to map

Post by wollomat »

Off course you can see the distortion, look at the towers in the east, or the trees, which seem to point towards the origin.

With 10 points, perspective distortion seems to work pretty smooth. However, the missing Z component seems to have an effect, as you can see in this plot.

Is there a way, to also map Z coordinates to the perspective filter?

Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Radial distortion - from screenshot to map

Post by snibgo »

Oh, okay, then you have a 2-D projection of a 3D-view. That isn't distortion, but simple projection, aka perspective.

IM is a 2-D image processor. It doesn't know about a third dimension. If you know the Z-value (height) of all the pixels, you can give all the data to a 3-D processor such as Blender or Povray, and then view it however you want.

Yes, with IM you could create a distortion map that would for example move the tops of the trees and towers to be over their bases, but what would you put where the tops used to be?
snibgo's IM pages: im.snibgo.com
wollomat
Posts: 4
Joined: 2016-10-22T02:47:36-07:00
Authentication code: 1151

Re: Radial distortion - from screenshot to map

Post by wollomat »

Allright, then I will have a look at Blender. I think my issue here is resolved, in case anyone wants to know what I did:

convert map_source.png -distort Perspective "$(cut -d" " -f1,2,3,4 coords.txt)" map_dest.png
with a file coords.txt in the following format:

Xs Ys Xd Yd #description
...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Radial distortion - from screenshot to map

Post by fmw42 »

I have not followed this discussion very closely. But as a point of interest, with a vertically downward look with a frame (pinhole or normal lens) perspective view camera, you would have terrain relief distortion. Taller terrain looks more distance from nadir than it really is. In one of my past careers, I created algorithms to do orthorectification that had to take this into account. Your image reminded me of that issue.
Post Reply