You can copy all the GeoTIFF metadata from the georeferenced TIFF file to the non-georeferenced one using the gdalcopyproj utility from GDAL, or using Python with the rasterio or gdal library.
If you have GDAL installed, run:
gdalcopyproj geotiff.tif non_geotiff.tif
This copies the projection and georeferencing metadata.
If you prefer Python, use rasterio to copy the metadata:
from rasterio.shutil import copy
geo_tiff_path = "geotiff.tif"
non_geo_tiff_path = "non_geotiff.tif"
output_tiff_path = "output_geotiff.tif" # New file with metadata
# Open the geotiff to read metadata
with rasterio.open(geo_tiff_path) as src:
# Copy the non-georeferenced image and apply metadata
copy(non_geo_tiff_path, output_tiff_path, **meta)
print("GeoTIFF metadata copied successfully!")
src_ds = gdal.Open("geotiff.tif", gdal.GA_ReadOnly)
dst_ds = gdal.Open("non_geotiff.tif", gdal.GA_Update)
# Copy georeferencing information
geo_transform = src_ds.GetGeoTransform()
projection = src_ds.GetProjection()
dst_ds.SetGeoTransform(geo_transform)
dst_ds.SetProjection(projection)
print("GeoTIFF metadata copied successfully!")
This ensures that the georeferencing information (coordinate system, projection, and geotransform) is copied correctly.
Would you like any additional modifications or explanations? 😊