Skip to content

Commit

Permalink
added utils scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lcmrl committed Mar 12, 2024
1 parent a1bd86f commit 14409f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/apply_masks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
from pathlib import Path
from PIL import Image
import numpy as np

img_dir = Path(r"/home/luca/Desktop/IMC24/GlassCup/original")
size = (1300, 3288)
out_dir = Path(r"/home/luca/Desktop/IMC24/GlassCup/outs")

images = os.listdir(img_dir)

for img_name in images:
img = Image.open(img_dir / img_name)
mask = Image.new("RGB", (size[0], size[1]), color="black")
img.paste(mask, (0, 0))
img.save(out_dir / img_name)
27 changes: 27 additions & 0 deletions scripts/skip_x_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil


def save_every_x_image(source_folder, output_folder, x):
# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)

# Get a list of all files in the source folder
files = os.listdir(source_folder)

# Iterate through the files and copy every x-th image to the output folder
for i, file_name in enumerate(files):
if i % x == 0:
source_path = os.path.join(source_folder, file_name)
output_path = os.path.join(output_folder, file_name)
shutil.copy2(source_path, output_path)
print(f"Copying {file_name} to {output_folder}")


# Replace 'source_folder', 'output_folder', and 'x' with your actual values
source_folder = "./full_res/images"
output_folder = "./skip"
x = 10 # Change this to the interval you desire

save_every_x_image(source_folder, output_folder, x)

0 comments on commit 14409f3

Please sign in to comment.