You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20_Final_Project/compare.py

54 lines
1.4 KiB
Python

import os
from glob import glob
img_dir = 'C:/Users/pinb/Desktop/imgs'
mask_dir = 'C:/Users/pinb/Desktop/masks'
names = ['gold_ii',
'gold_ie',
'gold_io',
'gold_ee',
'gold_ei',
'gold_eo',
'gold_oi',
'gold_oe',
'gold_oo',
'silver_ii',
'silver_ie',
'silver_io',
'silver_ee',
'silver_ei',
'silver_eo',
'silver_oi',
'silver_oe',
'silver_oo']
list_imgs = glob(os.path.join(img_dir, '**', '*.png'), recursive=True)
list_masks = glob(os.path.join(mask_dir, '**', '*.png'), recursive=True)
remove_file = []
# 마스크 파일 이름 목록 생성 (확장자 제거 및 '_mask' 추가)
list_imgs_basenames = set([x.replace('_mask', '').replace(mask_dir, img_dir) for x in list_masks])
# list_imgs에서 list_masks에 없는 파일 찾기
imgs_to_delete = [mask for mask in list_imgs_basenames if mask not in list_imgs]
print(len(list_imgs))
print(len(list_masks))
print(len(imgs_to_delete))
print(imgs_to_delete)
masks_to_delete = set([x.replace('.png', '_mask.png').replace(img_dir, mask_dir) for x in imgs_to_delete])
for mask in masks_to_delete:
os.remove(mask)
print(f'Deleted: {mask}')
list_imgs = glob(os.path.join(img_dir, '**', '*.png'), recursive=True)
list_masks = glob(os.path.join(mask_dir, '**', '*.png'), recursive=True)
print(len(list_imgs))
print(len(list_masks))