有没有办法从gdal阵列和图获得RGB?

问题描述

问题: 我的卫星图像包含多个波段(即MSI)。我正在处理图像以提取波段,进行聚类(KMeans),组合索引(例如NDWI),但是我无法获得简单的RGB输出

我尝试过的事情:

data = gdal.Open("myfile",gdal.GA_ReadOnly)
bands = [data.GetRasterBand(k + 1).ReadAsArray() for k in range(data.RasterCount)]
im = np.stack(bands,2)

# attempt 1
rgb = im[:,:,[4,2,1]] #see first included image for output
plt.imshow(rgb)
plt.show()

# attempt 2
red = bands[4]
green = bands[2]
blue = bands [1]
rgb = np.zeros((red.shape[0],red.shape[1],3))
rgb[:,0] = red
rgb[:,1] = green
rgb[:,2] = blue #see secondincluded image for output

plt.imshow((rgb * 255).astype(np.uint8))

在两种情况下,图像输出都是这种奇怪的绿色,我不确定为什么也不如何将其显示为RGB。有什么想法吗?

Attempt 1

Attempt 2

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)