from osgeo import gdal import numpy as np from netCDF4 import Dataset import matplotlib.pyplot as plt import rasterio from rasterio.plot import show # base_file = 'AT_900_S2_10m_256'; # base_file = 'AT_316_S2_10m_256'; # base_file = 'AT_539_S2_10m_256'; base_file = 'AT_688_S2_10m_256'; data = Dataset('image/'+base_file+'.nc') fp = 'masks/'+base_file+'.tif' img = rasterio.open(fp) time_slice = 0 # 0 to 5 B2 = np.array(data['B2'][time_slice,:,:]) B3 = np.array(data['B3'][time_slice,:,:]) B4 = np.array(data['B4'][time_slice,:,:]) B8 = np.array(data['B8'][time_slice,:,:]) fig, (b2, b3, b4, b8) = plt.subplots(1,4,figsize=(20,10)) b2.imshow(B2); b2.set_title('B2') b3.imshow(B3); b3.set_title('B3') b4.imshow(B4); b4.set_title('B4') b8.imshow(B8); b8.set_title('B8') fig, (extent, boundary, distance) = plt.subplots(1,3,figsize=(14,10)) extent_img = img.read(1) boundary_img = img.read(2) distance_img = img.read(3) show(extent_img, ax=extent, title='extent') show(boundary_img, ax=boundary, title='boundary') show(distance_img, ax=distance, title='distance')
基本的にB8のNIR画像から情報が抽出されている