Spaces:
No application file
No application file
File size: 1,177 Bytes
907462b | 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 | import numpy as np
import os
from PIL import Image
data_source = "/vol/data/histo_datasets/SegPC/TCIA_SegPC_dataset/"
splits = ["train", "validation"]
for s in splits:
images_list = os.listdir(data_source + s + "/x/")
masks_list = os.listdir(data_source + s + "/y/")
for i in images_list:
short_masks_list = [m for m in masks_list if i[:-4] == m[:-6]]
j = 0
for m in short_masks_list:
if j == 0:
mask = np.array(Image.open(data_source + s + "/y/" + m))
if len(mask.shape) == 3:
mask = mask[:, :, 0]
mask = np.where(mask == 20, 1, mask)
mask = np.where(mask == 40, 2, mask)
else:
additional_mask = np.array(Image.open(data_source + s + "/y/" + m))
if len(additional_mask.shape) == 3:
additional_mask = additional_mask[:, :, 0]
mask = np.where(additional_mask == 20, mask + 2*j -1, mask)
mask = np.where(additional_mask == 40, mask + 2*j, mask)
j += 1
Image.fromarray(mask).save(data_source + s + "/masks_png/" + m[:-6] + ".png")
|