1

Starting Situation: I have a distorted image, for example a geographic map with a grid. The distortion is of that kind: At the top of the map 10° geographic latitude correspond to 30 px, but at the bottom of the image 10° latitude correspond to only 10 px.

Aim: Now I want to scale the image, that 10° latitude correspond to let's say 20 px all over the image.

Let me illustrate the problem a litte more:

Starting situaiton: Image with an overall height of 100 px:

Area 1 - 30 px height

Area 2 - 25 px height

Area 3 - 20 px height

Area 4 - 15 px height

Area 5 - 10 px height

Aim: Image overall height stays constant (100 px), but now the areas should be of equal height:

Area 1 - 20 px height

Area 2 - 20 px height

Area 3 - 20 px height

Area 4 - 20 px height

Area 5 - 20 px height

If this can be achieved with other software than imagemagick, hints are welcome, too. Thanks for your replies in advance.

2 Answers2

1

Now I found out the tranformation function between my starting map and the map I desire:

f(y_px) = 200 (-0.5 + 0.01 * sqrt(150 + y_px))

This can be done by any fitting software.

Now I succesfully transformed the map using the "-fx" parameter and a 'custom matrix':

convert -monitor -size 100x100 xc:       map-starting.png  \
        -virtual-pixel Black  -interpolate NearestNeighbor \
        -fx "xx =  i ;
             yy = 200 (-0.5 + 0.01 * sqrt(150+ j));
             v.p{xx,yy}" \
        map-aim.png

map-aim.png is what I wanted ;)

0

It's not possible to correctly rescale and reproject map images with just a raster image processing tool like ImageMagick. You need a tool that is capable of computing a proper image transformation taking into account the change of map projection. You will also need projection metadata about your image, either in the image itself (if it is some format like GeoTIFF) or with associated metadata header files if it is a raw raster format like PNG or JPEG.

I suggest you look at the Geospatial Data Abstraction Library GDAL. It is a library that contains command line tools to allow you to properly reproject and transform many kinds of raster map images.

paisanco
  • 4,098
  • 6
  • 27
  • 33
  • OK, let's say, I know the projection function respective inverse function. – tom.kissinger Jul 19 '15 at 20:02
  • It's not possible to be more specific unless you edit your question to specify the original projection and how the metadata for the map is stored. – paisanco Jul 19 '15 at 23:15
  • False! See my solution! – tom.kissinger Jul 20 '15 at 09:08
  • Your "solution" does not preserve proper scaling from pixel coordinates to latitude and longitude. See http://stackoverflow.com/questions/14329691/covert-latitude-longitude-point-to-a-pixels-x-y-on-mercator-projection and http://stackoverflow.com/questions/5983099/converting-longitude-latitude-to-x-y-coordinate. If you don't care about that you should edit your question to say so. – paisanco Jul 21 '15 at 00:58