2

I't trying to mosaic a GeoTiff raster against another. Initially, they were both georeferenced in WGS-84 CRS. Using OpenCV, I calculated a homography transformation (a 3x3 projection matrix), that transforms an image to fit the other - I did it using rasters converted to JPEG images. Then, using OpenCV function warpPerspective, I applied my homography to the image and obtained a JPEG mosaic.

Now, I want to apply that transformation matrix to the GeoTiff raster and warp it along with it's geospatial information. However, I can't find an GDAL/osgeo function that would do that: gdal.Warp() seems to be doing something else entirely.

So, my question is: is there a function in GDAL that would accept my raster image and my transformation matrix and output the correctly transformed raster with modified geospatial information?

If not, is there a possible workaround to achieve that?

0

This solution requires using OpenCV 4.x and GDAL in python

You may want to try an affine transform between two images. cv.estimateAffine2D which gives you a 2x3 matrix

Get the transform of the pixel x,y coordinates of the second image to the first

warpedx = A[0,0]*x + A[0,1]*y + A[0,2]
warpedy = A[1,0]*x + A[1,1]*y + A[1,2] 

next you can validate by getting the those pixel coordinates and check if they match the original images pixel coorindates

xoff, a, b, yoff, d, e = ds.GetGeoTransform()
xp = a * x + b * y + xoff
yp = d * x + e * y + yoff

if the two points now match, go ahead and align the images and write the image with an updated geotransform

New contributor
Evan O'Keeffe is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.