3

I have download raw landsat 8 image with Rasterio. The image was download from GEE. . The image has 11 bands. I'm trying to display the image with grey scale/color scale as DN values, but for some reason I get the image in white values.

This is how I open the image and try to dusplay it:

#import required libraries
import rasterio
from rasterio import plot
import matplotlib.pyplot as plt
from rasterio.plot import show
%matplotlib inline

#open the raster
src=rasterio.open('16092020_landsat.tif')

#display one band:
plt.imshow(src.read(1), cmap='pink')

enter image description here

#RGB image
plt.figure(figsize=(20,10))
show(src.read([4,3,2]),transform=src.transform,title='Image- bands 4,3,2 IN 0-255 Values')

enter image description here

I get this image with correct coordinates but is white. When I try to plot the pixels as histogram with the RGB I get empty plot: enter image description here

When I run the same script with sentinel2 reflectance all works so I don't understand why here I get nothing,

My end goal: to be able to show the Landsat8 image as well.

edit: I suspect it has to do with the values of the Landat as they are between 0-25k

2 Answers 2

2
+50

You need to scale your data. The docs for imshow say:

The Normalize instance used to scale scalar data to the [0, 1] range before mapping to colors using cmap. By default, a linear scaling mapping the lowest value to 0 and the highest to 1 is used. This parameter is ignored for RGB(A) data.

So when you display one band, matplotlib is rescaling it for you, but not when you display multiple.

Do something like this to rescale to 8-bit values:

import numpy as np

data = src.read([4,3,2])
norm = (data * (255 / np.max(data))).astype(np.uint8)
plt.imshow(norm)

Or replace 255 with 1 and omit the astype if you need floats between 0 and 1

1

I had the same question as you and solved it like this.

show(rgb.read([4,3,2])/4000,transform=src.transform,title='Image-bands 4,3,2 IN 0-255 Values')

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.