Systeme D

4 December 2007

Quadrilateral to square



The above images make me happier than any two slightly blurry map scans have any right to.

On the left you can see a map scan and an arbitrary quadrilateral drawn on it. On the right you can see the area from said quadrilateral, neatly resized into a perfect square.

As yet the code is slow (because it's in pure Perl, rather than using Imager's amazing transform2 function), and the results a bit fuzzy (because I really need to do it at high resolution and then scale down). But I'm really chuffed to have got the basic principle working. It's an inverse mapping, i.e. the code loops over every pixel in the square and finds the corresponding pixel in the quadrilateral (rather than vice versa), so you don't get any holes in the image.

This is the first step in getting the New Popular Edition properly rectified and working as a background layer in Potlatch. There's a lot of effort ahead plotting anchor points for each sheet, followed by some hairy gdal work, but this is the single biggest obstacle overcome. And yes, I will, of course, publish the finished source code.


Comments

Beware! I've had some experience at rectifying New Pop OS maps and one thing that rang alarm bells, though I ignored it at the time, is that the squares at the sides are not always the same size as the other squares! Quite often they're more rectangular by (off the top of my head guess) 10% or more, certainly visibly different in size. from memory it looked like the printed grid was "open" at the side printed separately from the surrounding "collar".

When I came across this I thought a proper solution would be not to warp to squares, but to shear/warp the image so the vertical lines were all vertical, and the horizontal lines were all horizontal. Of course that then falls over on long creases. So perhaps a more complete solution is to properly rectify the center squares and simply "straighten" the squares at the edges.

Then again we're only talking a few percent so YMMV.

Posted by Andrew Rowbottom on 4.12.07 16:27

I'm currently rectifying each 10km x 10km square with its own set of four anchor points - certainly don't think I can rely on just four points for the whole sheet. This is working ok on the test sheet, but if it proves too inaccurate I can always further divide it into 5km x 5km, or even a 1km-wide strip at the edges, or whatever. (Subject of course to not dying of boredom while plotting the anchor points...!)

Posted by Richard on 5.12.07 16:31

Posted by hairy nude mature woman women on 7.6.08 17:36

Posted by mouth open cum shot drive on 20.6.08 20:26


Add a comment

Your name:

E-mail address: 

Comment:

your comment. (E-mail addresses will not be visible, but a server-based mail link will be provided. To guard against spam, no comments which include 'http' or 'www' will be published.)