I am trying to plot points (latitude, longitude) inside a raster image in Python. First, I read the image using
rasterio and plot it using the same package, after transform the image from
uint16 to Byte (
#Transform to uint8 def scale8bit(image): scale = float(256) / (image.max() - image.min()) return np.clip(np.round(np.multiply(image, scale)), 0, 255).astype(np.uint8) #Read image and plot visible bands src = rasterio.open(path) array_8b = img_as_ubyte(img_as_float(src.read([3, 2, 1]))) a = scale8bit(src.read([3, 2, 1]))
Now, I have some WKB points which coincide --as far as I can tell from the data-- with the bounding box of the image. Hence, I am trying to run the following in order to visualize the images and the points (read using
from shapely import wkb from rasterio import plot.show for i, geom in zip(selected_images_paths[0:10], subset_images["geom"][0:10]): #Open file using rasterio and change to int8 src = rasterio.open(i) src_8bit = scale8bit(src.read([3, 2, 1])) #Graph! fig, ax = plt.subplots(figsize=(30, 30)) plot.show(src_8bit) #Open geom with shapely geom_wkb = wkb.loads(geom, hex = True) x,y = geom_wkb.xy ax.scatter(x, y, marker = 'o', s=50, c='r')
The units of the graphs are clearly on color intensity and not in long, lat, which are the units of the x,y tuple. I've tried different options, but I can figure out how to overlap both data sets.
Is there something wanting, or should I take another approach?
EDIT I have been following the code described in this question (Plot shapefile on top of raster using plot and imshow from matplotlib). Nonetheless, the result is sub-optimal.
When I use
ax = plt.gca() to set the axes in the subplot, the
fig definition is completely ignored for some images and the resulting figure is small. I think the error must be on the
fig definition, but I've tried other suggestions in the documentation without success.