# How to transform an aerial image

This is the first time I'm diving a little deep into images and computer vision. I have an aerial image taken from a drone (I know the pitch, roll, yaw of the drone and the angle of the camera relative to north). How do I transform the image so that it looks as if it is taken from the top? I want to map latitude, longitude on the aerial image to pixels (I know the lat, lon of all four corners of the image) and my understanding is that I need to transform the image before I can interpolate and map a new lat,lng pair to pixels.

Suppose you're imaging a square with sides of length $d$, and you're a height $h \gg d$ above the square. You're tilted in one dimension by $\theta$. Then the center of the square appears displaced by $-h \sin \theta$ and its apparent width along that dimension is $d \cos \theta$, not $d$. So, what object would be imaged onto a single pixel of size $d_p$? It would need to be a rectangle, displaced from the image center by $h \sin \theta$. Its width along the tilted dimension would have to be $d / cos \theta$, but along the untilted dimension it should still be $d$.
So after correction, the image consists of rectangular pixels of width $d / \cos \theta$. There's no transform on the raw image data that will implement this directly. However, it's easy to write a function that will return the value of the image at a given lat/long.