imagematrixgeometrytransformation# locating a point in a 2d image that was warped

I have an original image that has been "warped". Can someone help me with the math to calculate where a given point from the original image would show up in the warped one?

I have an image with a rectangle inside of it. I know where, in the flat image the points A, B, C, D, E and F are.

```
+------------------------------------------------+
| |
| A B |
| +-------------------+ |
| | | |
| | •F | |
| | | |
| | | |
| | | |
| | •E | |
| +-------------------+ |
| C D |
| |
+------------------------------------------------+
```

The new image (A') was create due to an imperfect setup of a camera, which has warped the image. I now have A',B',C'D',E',F'.

I don't necessarily want to "unwarp" the image, I just want the coordinates in the new coordinate space, where the point has ended up. Given that I know where A, B, C, D, E, F, A', B', C', D' and E' (in their respective image), is that enough information to simply calculate where the new E' point should be in the image?

I feel that this is a 3D matrix transformation, but the math is beyond me and I'm trying to figure out the equations that would just solve for (E')s new coordinates. I guess technically this is a 2D object that was projected through 3D space onto a 2D surface.

```
+------------------------------------------------+
| |
| A' |
| +--------- B' |
| | -----------+ |
| | | |
| | •F' | |
| | | |
| | | |
| | | |
| | •E' | |
| | -------+ |
| +------------ D' |
| C' |
| |
+------------------------------------------------+
```

If I need to add another point (G and G'), in order to solve for E', I could add it.

What I've been able to understand is that this would be solving a series of simultaneous equations, but I'm not sure how many "knowns" are needed to solve for E'(x,y).

I'm doing this in iOS (Objective C), but I'm not so concerned with the actual coding, I'm really just trying to find the solution matrix (if that is the right term).

Solution

This transformation (2D to 2D with a perspective effect) is a so-called homography, which can be described with 8 coefficients (`a`

to `h`

):

```
X = (a.x + b.y + c) / (g.x + h.y + 1)
Y = (d.x + e.y + f) / (g.x + h.y + 1)
```

You can easily linearize these equations as:

```
a.x + b.y + c - g.x.X - h.y.X = X
d.x + e.y + f - g.x.Y - h.y.Y = Y
```

You solve them by taking four points (the four corners), which give you eight equations in eight unknowns, and from there you can transform any new point.

As the inverse of an homography is also an homography, you can apply this resolution in two ways (upright to distorted or conversely). Make sure that the unknown coordinates that you are looking for appear as `(X, Y)`

(rather than `(x, y)`

) in the above developments.

- How to preload CSS images?
- Highlighting smiles features with rdkit
- Change color of PNG image via CSS?
- How can I draw a string of text onto the pixels of a BGR image so that the text is readable when displayed, c++?
- Extracting the least significant bit in a very large TIFF/JPEG image using open source library
- Image cropper Android Studio Kotlin
- Python - Extract a PDF page as a jpeg
- how to make the blur effect with react-native?
- Flutter: Base64: Invalid length, must be multiple of four (FormatException)
- PIL jpeg, how to preserve the pixel color
- Can't set button image list
- How to replace color of PNG image using CSS?
- Dompdf remote image is not displaying in pdf
- Image not drawning correctly in <img>
- WebP encoder/decoder in go
- Images are not showing while you're not logged in on wordpress website
- Isn't there an easy way to pinch to zoom in an image in SwiftUI?
- How do I maintain image size when using a colorbar?
- How to Save a Matrix as a PNG Image and Reload it to Recover the Original Matrix
- Is there a faster way to copy bitmap data when creating a new image?
- “Diff” an image using ImageMagick
- image from uint16 array from serial port
- Tailwind ObjectFit directives (like object-cover, object-fit, etc.) have no effect
- SDL3 Texture Create returns always NULL
- How can I crop different images using Laravel Varbox?
- Dynamically load and display images from disk using eframe/egui
- How do I add a resource as a bitmap to my C# project in Visual Studio 2022?
- ImageIO.read returns NULL, with no errors
- Html2canvas / jspdf cut off image
- How can I show image in HttpResponseMessage.Content.Headers.ContentType