Image Replacement Algorithm

I am developing (the last 3 hours) a small project that I am doing in C # to help me choose a home.

In particular, I put crime statistics in an overlay on Google maps to find a good area.

Here is an example: http://otac0n.com/Demos/prospects.html

Now I manually discovered that Lat and Lng correspond to the corners of the map offset in the example, but I have a few more maps to overlay.

My new application allows me to select a landmark and point to an image to associate a pixel with LatLng. Sort of:

locations.Add(new LocationPoint(37.6790f, -97.3125f, "Kellogg and I-135")); // and later... targetPoint.Pixel = FindPixel(mouseEvent.Location); 

So, I put together a list of pixel / latlng combinations and now I would like to convert the image (using affine or non-affine transforms).

The goal is to make every street line. Given a good map, the only conversion needed would be a turn to align the map up from north to south (and for now I would be happy with that). But I'm not sure where to start.

Does anyone have any experience doing image conversions in C #? How can I find the correct rotation to make the map level?

After solving well-made cards, I would eventually like to overlay the drawn cards. This obviously entails serious distortion of the final image and may go beyond the scope of this first iteration. However, I would not want to develop a system that in the future will not be available for this system.

+4
source share
3 answers

I'm not sure what exactly you want to accomplish, but if you want to place more than three points on one map more than three points on another, you can basically go in two ways:

  • You can try to create a triangular grid on top of your points, and then apply another affine transformation inside each triangle and get a piecewise linear transformation. To get the grid on the right, you probably need to do something like triangulating Delaunay points, for which qhull is likely to be your preferred option.
  • You can move on to a higher order transformation, such as quad distortion , but it will probably be difficult to find a solution that works for any number of points in a common position. Find yourself a good book of finite element methods and read the chapter on higher order isoparametric elements, either Lagrangian or random, which will provide you with the correct display of many points at many points. Here are some links ( 1 and 2 ) to set you on your way. But keep in mind that the mathematical content is intense ...
+3
source

In 2D space, an affine transformation can be defined by two sets of three nonlinear two-dimensional points. In C #, you can use the following procedure to calculate the corresponding matrix:

  public static Matrix fit(PointF[] src, PointF[] dst) { Matrix m1 = new Matrix(new RectangleF(0, 0, 1, 1), src); m1.Invert(); Matrix m2 = new Matrix(new RectangleF(0, 0, 1, 1), dst); m2.Multiply(m1); return m2; } 

It works for both array arguments having 3 elements.

If you only need rotation and translation, you can use the following procedure:

  public static Matrix fitOrt(PointF src1, PointF src2, PointF dst1, PointF dst2) { return fit(new PointF[] { src1, src2, ort(src1, src2) }, new PointF[] { dst1, dst2, ort(dst1, dst2) }); } public static PointF ort(PointF p, PointF q) { return new PointF(pX + qY - pY, pY - qX + pX); } 

If you want to find the best approximation between two sets of several points, you can start with this http://elonen.iki.fi/code/misc-notes/affine-fit/

+2
source

Beautiful.

So, thanks to Jamie's guide, I found this:

Delaunay triangulation in .NET 2.0

http://local.wasp.uwa.edu.au/~pbourke/papers/triangulate/morten.html

At this point, it is greatly simplified for lerping.

0
source

Source: https://habr.com/ru/post/1285884/


All Articles