'After Georeferencing the jpg file using GDAL, Can I know which pixel of the jpg file has been moved to which pixel of the tif file?

Fist of all, I'd like to say thanks to everyone who will give me answer.

I wanna get the geo-coordinates of each pixel of the drone image(jpg).

So I did georeferencing on drone image(jpg) using GDAL and GCP info.

And it also got the geo-coordinates of each pixel of tif file obtained through georeferencing.

But what I wanna know is the geo-coordinates of each pixel of jpg file.

So I have to find which pixel of jpg was moved to in tif.

Can I know which pixel of the jpg file has been moved to which pixel of the tif file?

Here is the code and pre-georeferencing image (jpg) and post-georeferencing image (tif)

from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt

ds = gdal.Open('data/DJI_0165_cali.jpg')

gcp_list = []
gcp = gdal.GCP(392689.698, 294905.073, 0, 3702, 970)
gcp_list.append(gcp)
gcp = gdal.GCP(392727.269, 294776.388, 0, 1981, 996)
gcp_list.append(gcp)
gcp = gdal.GCP(392765.136, 294638.506, 0, 283, 988)
gcp_list.append(gcp)
gcp = gdal.GCP(392732.312, 294639.35, 0, 391, 615)
gcp_list.append(gcp)
gcp = gdal.GCP(392703.634, 294770.92,0, 1996, 698)
gcp_list.append(gcp)
gcp = gdal.GCP(392670.438, 294885.556,0, 3519, 669)
gcp_list.append(gcp)

ds_gcp = gdal.Translate('output.tif', ds, GCPs=gcp_list)
ds_gcp = gdal.Warp('output.tif',ds_gcp, dstSRS='EPSG:3857', dstNodata = np.nan)

def pixel(file,dx,dy):
    px = file.GetGeoTransform()[0]
    py = file.GetGeoTransform()[3]
    rx = file.GetGeoTransform()[1]
    ry = file.GetGeoTransform()[5]
    x = dx*rx + px
    y = dy*ry + py
    return x,y

pixel(ds_gcp,1500,1500)

pre-georeferencing image (jpg)

enter image description here

post-georeferencing image (tif)

enter image description here



Solution 1:[1]

What you need is called GDALGCPTransform in the C++ API: https://gdal.org/doxygen/gdal__alg_8h.html

As far as I know there is no Python binding but it seems that it is present in rasterio: https://rasterio.readthedocs.io/en/latest/api/rasterio.transform.html

You can run it on the dataset that is the output of gdal.Translate.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmomtchev