1

I am trying to batch georeference a set of raster images using the GDAL function in python. For this, I georeferenced a raster image manually using QGIS and extracted the values of GCP as a CSV file. I then used the GCP points from the QGIS as the input and the SRC and CRC ESRI value I used was 102025. For some reason, the output is getting inverted. I tried to change the projection, modified pixel values and still, the output image is inverted.

Please find the attached code and the set of Input and Output Images.

# Skipping the input CSV extraction of the program (I did it using pandas data frame)

#list of GCP points
gcp_list=[]
for index, rows in modified_df.iterrows():
   gcps = gdal.GCP(rows.mapX, rows.mapY, 1, rows.pixelX, rows.pixelY )
   gcp_list.append(gcps)
   
# Set spatial reference:
sr = osr.SpatialReference()

# Projection- taken from the website of ESRI 102025
sr.ImportFromProj4("+proj=aea +lat_1=15 +lat_2=65 +lat_0=30 +lon_0=95 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs") 

# Final Projection
ds = gdal.Open( output_fn, gdal.GA_Update )
wkt = ds.GetProjection()
gcpcount = ds.GetGCPCount( )

#Inversion is happening here
ds.SetGCPs( gcp_list, wkt )

#Clear the output file if it is opened anywhere else
ds=None

Input Image

Input Image

Output Image using GDAL

GDAL Output

Output of QGIS

Output of QGIS

Projection of the GDAL output in OSM

GDAL output projection in OSM

GCP Points

The value 1200 was added to all the pixel values of the Y coordinate because the pixel values were negative.

Georeferenced using ESRI: 102025 both in QGIS and GDAL.

GCP points

0
2

You should multiply Y pixel coordinates by -1 instead of adding a constant value.

Sometimes software (QGIS georeferencing tool in your example) shows negative pixel coordinates (so the value decreases from top to bottom) but pixel coordinates are usually 0 at the top and increasing to the bottom of the image.

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.