2

I have a list of images (read with tifffile.imread) and the coordinates (xmin, xmax, ymin, ymax) stored in a list. Suppose the images cover an area of 100 by 100 meters. Some of the areas are missing. I would like to stitch the images together to tiles of 1000 by 1000 meters. The missing areas should be included in the tile as [255,255,255].

The following code illustrates stitching along the y-axis, without filling the missing images:

import numpy as np
import tifffile
import pandas as pd

images= [...]  #this is a list of images read with tifffile
"""
# Variables I have not used, but could be used
listCoordinates = [[xmin, xmax, ymin, ymax], [xmin, xmax, ymin, ymax],...]
imempty = = np.ones((100,100,3), np.int16)*255
aoi = "foo.shp" # shape file with area of interest, polygon
dframe = pd.DataFrame({'images':images, 'coord':listCoordinates})
"""
num = 10
xmax = 500  #starts at x coordinate of 500 
xmaxLimit = xmax + num*1000
i = 0

startim = images[i]
while xmax <= xmaxLimit :
    i += 1
    img = images[i]
    startim = np.concatenate((img, startim ), axis=0)
    xmax = xmax + 1000

I am now looking for a function concatenating the 10 strips of np.concatenate((...), axis=0), with np.concatenate((...), axis=1) by looking up the coordinates.

  • 1
    did you consider using gdal_merge.py ? – radouxju Nov 12 at 10:57
  • Thanks for the hint, it indeed looks like what I need. – se.ka Nov 12 at 11:15
  • Update: It indeed worked out with gdal_merge -- life sometimes can be so easy. Thanks! – se.ka Nov 13 at 12:00

Your Answer

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

Browse other questions tagged or ask your own question.