43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
|
import os
|
||
|
|
||
|
# 定义图像和掩码目录的路径
|
||
|
image_dir = r'C:\Users\t2581\Desktop\LoveDA\Train\pv\images_png'
|
||
|
mask_dir = r'C:\Users\t2581\Desktop\LoveDA\Train\pv\masks_png_convert'
|
||
|
|
||
|
# 列出每个目录中的文件
|
||
|
image_files = os.listdir(image_dir)
|
||
|
mask_files = os.listdir(mask_dir)
|
||
|
|
||
|
# 对列表进行排序,方便比较
|
||
|
image_files.sort()
|
||
|
mask_files.sort()
|
||
|
|
||
|
# 统计每个目录中的文件数量
|
||
|
num_images = len(image_files)
|
||
|
num_masks = len(mask_files)
|
||
|
|
||
|
# 打印文件数量
|
||
|
print(f"图像数量: {num_images}")
|
||
|
print(f"掩码数量: {num_masks}")
|
||
|
|
||
|
# 检查文件名是否匹配
|
||
|
mismatched_files = []
|
||
|
for image_file in image_files:
|
||
|
# 替换扩展名
|
||
|
corresponding_mask = image_file.replace('.jpg', '.png')
|
||
|
if corresponding_mask not in mask_files:
|
||
|
mismatched_files.append((image_file, corresponding_mask))
|
||
|
|
||
|
# 如果有不匹配的文件,打印出来
|
||
|
if mismatched_files:
|
||
|
print("不匹配的文件:")
|
||
|
for mismatched_file in mismatched_files:
|
||
|
print(f"图像文件: {mismatched_file[0]}, 预期的掩码文件: {mismatched_file[1]}")
|
||
|
else:
|
||
|
print("所有文件都有对应的掩码。")
|
||
|
|
||
|
# 打印每个图像和对应的掩码路径
|
||
|
for image_file in image_files:
|
||
|
corresponding_mask = image_file.replace('.jpg', '.png')
|
||
|
print(f"图像文件: {os.path.join(image_dir, image_file)}, 掩码文件: {os.path.join(mask_dir, corresponding_mask)}")
|