I am trying to read a hyperspectral image in Uint16 .tif format and visualize it. I use GDAL in Python to read the data and everything works perfectly when I use matplotlib to show one band of the data (The first image). The image however becomes completely corrupted when I want to concatenate(stack) 3 different selected bands and visualize them. Here is the code:
import numpy as npimport structfrom osgeo import gdalfrom osgeo import ogrfrom osgeo import osrfrom osgeo import gdal_arrayfrom osgeo.gdalconst import *import matplotlib.pyplot as pltcube = gdal.Open(filename)bnd1 = cube.GetRasterBand(29)bnd2 = cube.GetRasterBand(19)bnd3 = cube.GetRasterBand(9)Now I turn each band into a ndarray:
img1 = bnd1.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize)img2 = bnd2.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize)img3 = bnd3.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize) and stack them to have a 3 band image
img = np.dstack((img1,img2,img3))f = plt.figure()plt.imshow(img) plt.show()I would appreciate any suggestion on it
here are the results:
أكثر...
import numpy as npimport structfrom osgeo import gdalfrom osgeo import ogrfrom osgeo import osrfrom osgeo import gdal_arrayfrom osgeo.gdalconst import *import matplotlib.pyplot as pltcube = gdal.Open(filename)bnd1 = cube.GetRasterBand(29)bnd2 = cube.GetRasterBand(19)bnd3 = cube.GetRasterBand(9)Now I turn each band into a ndarray:
img1 = bnd1.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize)img2 = bnd2.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize)img3 = bnd3.ReadAsArray(0,0,cube.RasterXSize, cube.RasterYSize) and stack them to have a 3 band image
img = np.dstack((img1,img2,img3))f = plt.figure()plt.imshow(img) plt.show()I would appreciate any suggestion on it
here are the results:
أكثر...