|
from main import get_nude |
|
import os |
|
from PIL import Image |
|
|
|
def create_grid_image(original, edited1, edited2): |
|
|
|
width, height = original.size |
|
grid = Image.new('RGB', (width, height * 3)) |
|
|
|
|
|
grid.paste(original, (0, 0)) |
|
grid.paste(edited1, (0, height)) |
|
grid.paste(edited2, (0, height * 2)) |
|
|
|
return grid |
|
|
|
def process_images(input_dir, output_dir, edit_function): |
|
|
|
if not os.path.exists(output_dir): |
|
os.makedirs(output_dir) |
|
|
|
|
|
for filename in os.listdir(input_dir): |
|
print(f"Processing {filename}") |
|
if filename.lower().endswith(('.png', '.jpg', '.jpeg')): |
|
base_filename, file_extension = os.path.splitext(filename) |
|
grid_filename = f"{base_filename}1{file_extension}" |
|
|
|
if os.path.exists(os.path.join(output_dir, grid_filename)): |
|
print(f"Skipping {filename}, already exists in output directory") |
|
continue |
|
|
|
|
|
file_path = os.path.join(input_dir, filename) |
|
|
|
|
|
original = Image.open(file_path) |
|
try: |
|
edited_images = edit_function(original) |
|
except Exception as e: |
|
print(f"Error processing {filename}: {e}") |
|
continue |
|
|
|
|
|
grid_image = create_grid_image(original, edited_images[0], edited_images[1]) |
|
|
|
|
|
grid_image.save(os.path.join(output_dir, grid_filename)) |
|
|
|
print(f"Saved {grid_filename}") |
|
|
|
process_images('./dataset', './dataset_result_grids', get_nude) |
|
|