23 lines
609 B
Python
23 lines
609 B
Python
![]() |
from PIL import Image
|
|||
|
import numpy as np
|
|||
|
import os
|
|||
|
from osgeo import gdal
|
|||
|
|
|||
|
|
|||
|
mask_dir = r"E:\datasets\wlk_right_448\mask" # 修改为你的mask文件夹路径
|
|||
|
|
|||
|
all_labels = set()
|
|||
|
|
|||
|
for file in os.listdir(mask_dir):
|
|||
|
if file.lower().endswith('.tif'):
|
|||
|
tif_path = os.path.join(mask_dir, file)
|
|||
|
dataset = gdal.Open(tif_path)
|
|||
|
if dataset is None:
|
|||
|
print(f"无法打开: {tif_path}")
|
|||
|
continue
|
|||
|
band = dataset.ReadAsArray()
|
|||
|
unique = np.unique(band)
|
|||
|
all_labels.update(unique)
|
|||
|
|
|||
|
print("所有mask中出现过的标签数字:", sorted(all_labels))
|