TransWikia.com

Using rasterio to show RGB image with nodata

Geographic Information Systems Asked by wsf1990 on December 19, 2020

This question is same as https://stackoverflow.com/questions/59132459/use-rasterio-show-rgb-image-with-nodata

I have a multiband image with nodata value (which is Landsat and been set nodata to 0). And I want to use rasterio show the image,But I found that the show function cant deal the nodata value with multiband image. And I had test that singleband image is well.My code like this:

with rio.open(path) as src:
    arr = src.read([1, 2, 3], masked=True)
    show(arr)

the image is like this:

rgb

This is the landsat image,You can find that the image is warped by black color,In this place the data is nodata and would be display as transparent.

How do I show nodata multiband img by rasterio?

One Answer

If you just want the no data areas to be white, then an easy and quick solution is to do:

arr[arr==0] = np.max(arr)
show(arr)

If you want it actually transparent because you are going to plot multiple data sets on the axes which need to overlap correctly, then there isn't an easy way, but I'd explore using 'matplotlib.pyplot.imshow', converting your dataset to float, and converting no data areas to 'np.nan'.

Answered by sbphd on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP