如何使用 OpenCV 从 HDF5 文件(来自 MOSDAC)绘制图像的边界?

发布于 2025-01-15 05:23:35 字数 1400 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文