semantic-segmentation/datasets_pro_code/read_mask.py
2025-05-30 09:26:49 +08:00

19 lines
478 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PIL import Image
import numpy as np
import os
from osgeo import gdal
mask_dir = r"E:\RSdata\wlk_right_448\mask_png_ori" # 修改为你的mask文件夹路径
all_labels = set()
for file in os.listdir(mask_dir):
if file.lower().endswith('.png'):
img = Image.open(os.path.join(mask_dir, file))
img = np.array(img)
unique = np.unique(img)
all_labels.update(unique)
print("所有mask中出现过的标签数字", sorted(all_labels))