| import cv2 | |
| import numpy as np | |
| import os | |
| image_folder = "masked_loss_training_data/images" | |
| mask_folder = "masked_loss_training_data/conditioning" | |
| image_files = os.listdir(image_folder) | |
| jpg_files = [f for f in image_files if f.endswith('.jpg')] | |
| for file_name in jpg_files: | |
| img = cv2.imread(os.path.join(image_folder, file_name), cv2.IMREAD_GRAYSCALE) | |
| _, bw_mask = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) | |
| output_file_path = os.path.join(mask_folder, os.path.splitext(file_name)[0] + '.png') | |
| cv2.imwrite(output_file_path, bw_mask) | |