Visualizing multi-band satellite images in Python

  Рет қаралды 12,406

Making Sense Remotely

Making Sense Remotely

Күн бұрын

In this tutorial, I explain how to visualize multi-band Landsat 8 satellite imagery as true- and false-color composites using Python and matplotlib. The basic procedure is: 1) read individual raster bands as array 2) rescale to 0 and 1 using minimum and maximum values (or percentiles or mean + - standard deviation for contrast enhancement) 3) stack arrays using numpy.dstack 4) plot RGB composite with plt.imshow()
Code:
from osgeo import gdal
import numpy as np
import matplotlib.pyplot as plt
def scaleMinMax(x):
return((x - np.nanmin(x))/(np.nanmax(x) - np.nanmin(x)))
def scaleCCC(x):
return((x - np.nanpercentile(x, 2))/(np.nanpercentile(x, 98) - np.nanpercentile(x,2)))
def scaleStd(x):
return((x - (np.nanmean(x)-np.nanstd(x)*2))/((np.nanmean(x)+np.nanstd(x)*2) - (np.nanmean(x)-np.nanstd(x)*2)))
ds = gdal.Open("Landsat8_20200423_B1-7.tif")
r = ds.GetRasterBand(4).ReadAsArray()
g = ds.GetRasterBand(3).ReadAsArray()
b = ds.GetRasterBand(2).ReadAsArray()
ds = None
rMinMax = scaleMinMax(r)
gMinMax = scaleMinMax(g)
bMinMax = scaleMinMax(b)
rgbMinMax = np.dstack((rMinMax,gMinMax,bMinMax))
plt.figure()
plt.imshow(rgbMinMax)
plt.show()
rCCC = scaleCCC(r)
gCCC = scaleCCC(g)
bCCC = scaleCCC(b)
rgbCCC = np.dstack((rCCC,gCCC,bCCC))
plt.figure()
plt.imshow(rgbCCC)
plt.show()
rStd = scaleStd(r)
gStd = scaleStd(g)
bStd = scaleStd(b)
rgbStd = np.dstack((rStd,gStd,bStd))
plt.figure()
plt.imshow(rgbStd)
plt.show()

Пікірлер: 23
Splitting raster data into equal pieces with GDAL in Python
15:40
Making Sense Remotely
Рет қаралды 10 М.
When deep learning meets satellite imagery
7:51
Preligens
Рет қаралды 118 М.
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
Sigma Kid Hair #funny #sigma #comedy
00:33
CRAZY GREAPA
Рет қаралды 41 МЛН
Half Year of Learning Game Development
3:59
NyeonPlay
Рет қаралды 247
How to generate NDVI Map of Sentinel satellite imagery with Python || Google Colab || Remote sensing
17:41
Study Hacks-Institute of GIS & Remote Sensing
Рет қаралды 1,3 М.
Time Series Forecasting with XGBoost - Advanced Methods
22:02
Rob Mulla
Рет қаралды 117 М.
Convert between CSV and GeoTIFF with GDAL in Python
28:11
Making Sense Remotely
Рет қаралды 20 М.
Introduction to Remote Sensing with Python
1:04:39
UCLA Office of Advanced Research Computing (OARC)
Рет қаралды 13 М.
Read and write raster files with GDAL in Python
11:07
Making Sense Remotely
Рет қаралды 44 М.
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН