-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |