如何使用 OpenCV 从 HDF5 文件(来自 MOSDAC)绘制图像的边界?
我有一个 MOSDAC 文件,我从中获取了特定云区域的图像。之后我使用阈值来获取特定值下的图像。但现在我想在 python (OpenCV) 中获取云的边界(我知道我们可以在 MATLAB 中使用 bwboundaries)。
我使用的代码:
import h5py
import cv2
import numpy as np
import matplotlib.pyplot as plt
fn = '3DIMG_30MAR2018_0000_L1B_STD.h5' #filename (the ".h5" file)
hf = h5py.File(fn, 'r')
hf.keys()
data = hf.get('IMG_TIR1')
data = data[0,:,:]
data=np.where(data>1022, np.nan, data)
Lat= hf.get('Latitude')
Lat = Lat[:,:]
Lat=Lat*0.0099999998
Lat=np.where(Lat>312, np.nan, Lat)
Long= hf.get('Longitude')
Long = Long[:,:]
Long=Long*0.0099999998
Long=np.where(Long>312, np.nan, Long)
X=Long[427:1421,804:1902]
Y=Lat[427:1421,804:1902]
Z=data[427:1421,804:1902]
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Z)
plt.xlim(60, 100)
plt.ylim(0, 40)
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Z)
plt.colorbar(label="Radiance", orientation="vertical")
plt.xlim(60, 100)
plt.ylim(0, 40)
#Threshold
Zn=np.where(Z>810, 1, 0)
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Zn, cmap='jet', vmin=0, vmax=1)
plt.colorbar(label="Radiance", orientation="vertical")
plt.xlim(60, 100)
plt.ylim(0, 40)
fig = plt.figure(figsize=(10,10))
plt.imshow(Zn, cmap='binary', vmin=0, vmax=1)
plt.colorbar(label="Radiance", orientation="vertical")
数据集链接:https://drive.google.com/file/d/1S78nEM2l5thIRJLkZKlVzaskRwDo-5Iu/view?usp=sharing
I have a MOSDAC file from which I obtained and image for a specific region with clouds. And after that I used thresholds to obtain an image under specific value. But now I want to obtain boundaries of the clouds in python (OpenCV) (I know that we can use bwboundaries in MATLAB).
Code that I used :
import h5py
import cv2
import numpy as np
import matplotlib.pyplot as plt
fn = '3DIMG_30MAR2018_0000_L1B_STD.h5' #filename (the ".h5" file)
hf = h5py.File(fn, 'r')
hf.keys()
data = hf.get('IMG_TIR1')
data = data[0,:,:]
data=np.where(data>1022, np.nan, data)
Lat= hf.get('Latitude')
Lat = Lat[:,:]
Lat=Lat*0.0099999998
Lat=np.where(Lat>312, np.nan, Lat)
Long= hf.get('Longitude')
Long = Long[:,:]
Long=Long*0.0099999998
Long=np.where(Long>312, np.nan, Long)
X=Long[427:1421,804:1902]
Y=Lat[427:1421,804:1902]
Z=data[427:1421,804:1902]
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Z)
plt.xlim(60, 100)
plt.ylim(0, 40)
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Z)
plt.colorbar(label="Radiance", orientation="vertical")
plt.xlim(60, 100)
plt.ylim(0, 40)
#Threshold
Zn=np.where(Z>810, 1, 0)
fig = plt.figure(figsize=(10,10))
plt.pcolor(X, Y, Zn, cmap='jet', vmin=0, vmax=1)
plt.colorbar(label="Radiance", orientation="vertical")
plt.xlim(60, 100)
plt.ylim(0, 40)
fig = plt.figure(figsize=(10,10))
plt.imshow(Zn, cmap='binary', vmin=0, vmax=1)
plt.colorbar(label="Radiance", orientation="vertical")
Link for the dataset: https://drive.google.com/file/d/1S78nEM2l5thIRJLkZKlVzaskRwDo-5Iu/view?usp=sharing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论