Skip to content

Instantly share code, notes, and snippets.

@Marcellofabrizio
Last active June 5, 2024 01:08
Show Gist options
  • Save Marcellofabrizio/0e861c88a4c8bea0c1b29aa4d5ad21ec to your computer and use it in GitHub Desktop.
Save Marcellofabrizio/0e861c88a4c8bea0c1b29aa4d5ad21ec to your computer and use it in GitHub Desktop.
Create Empty Labels
from PIL import Image
import sys
import os
import numpy as np
def create_empty_label_masks(input_directory, output_directory):
if not os.path.exists(output_directory):
os.makedirs(output_directory)
for filename in os.listdir(input_directory):
if filename.lower().endswith('.png'):
print('Creating empty label mask for file ' + filename)
image_path = os.path.join(input_directory, filename)
with Image.open(image_path) as img:
width, height = img.size
empty_mask = Image.fromarray(np.zeros((height, width), dtype=np.uint8))
output_path = os.path.join(output_directory, filename)
empty_mask.save(output_path)
input_directory = sys.argv[1]
output_directory = sys.argv[2]
create_empty_label_masks(input_directory, output_directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment