File size: 968 Bytes
818b5fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)