from osgeo import gdal from PIL import Image import csv # creating a image object im = Image.open(r'Nadia.tif') px = im.load() # Open tif file ds = gdal.Open('Nadia.tif') # GDAL affine transform parameters, According to gdal documentation xoff/yoff are image left corner, a/e are pixel wight/height and b/d is rotation and is zero if image is north up. xoff, a, b, yoff, d, e = ds.GetGeoTransform() def pixel2coord(x, y): """Returns global coordinates from pixel x, y coords""" xp = a * x + b * y + xoff yp = d * x + e * y + yoff return(xp, yp) # get columns and rows of your image from gdalinfo rows = 36+1 colms = 34+1 all_markers = [] if __name__ == "__main__": for row in range(0,rows): for col in range(0,colms): #print(pixel2coord(col,row)) if im.getpixel(pixel2coord(col,row)) != (0,0,0) or im.getpixel(pixel2coord(col,row)) != (0,0,0): all_markers.append(pixel2coord(col,row)) print(all_markers) with open('banana.csv', 'w') as f: # using csv.writer method from CSV package write = csv.writer(f) write.writerows(all_markers)