DIAS / utils /prepare_data.py
pythn's picture
Upload with huggingface_hub
818b5fb verified
raw
history blame contribute delete
968 Bytes
import os
import re
# Define your directories
image_dir = '/home/abdelrahman.elsayed/DIAS/images'
mask_dir = '/home/abdelrahman.elsayed/DIAS/masks'
# Rename images
for filename in os.listdir(image_dir):
if filename.endswith('.png') or filename.endswith('.jpg'):
print(filename)
test_name = filename.split("-")
print(test_name)
match = re.match(r'image_s(\d+)_i(\d+)\.png', filename)
if match:
new_name = f's{match.group(1)}.png'
os.rename(os.path.join(image_dir, filename), os.path.join(image_dir, new_name))
# print(new_name)
# Rename masks
for filename in os.listdir(mask_dir):
if filename.endswith('.png'):
match = re.match(r'label_s(\d+)\.png', filename)
print(filename)
if match:
new_name = f's{match.group(1)}_mask.png'
os.rename(os.path.join(mask_dir, filename), os.path.join(mask_dir, new_name))
print(new_name)