File size: 1,916 Bytes
72dddd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from main import get_nude
import os
from PIL import Image

def create_grid_image(original, edited1, edited2):
    # Create a new image with appropriate size to hold the three images (original, edited1, edited2)
    width, height = original.size
    grid = Image.new('RGB', (width, height * 3))
    
    # Paste the original and edited images into the grid
    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):
    # Create the output directory if it doesn't exist
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    # Loop through all files in the input directory
    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
            
            # Construct full file path
            file_path = os.path.join(input_dir, filename)

            # Process the image
            original = Image.open(file_path)
            try:
                edited_images = edit_function(original)
            except Exception as e:
                print(f"Error processing {filename}: {e}")
                continue

            # Create the grid image
            grid_image = create_grid_image(original, edited_images[0], edited_images[1])

            # Save the grid image
            grid_image.save(os.path.join(output_dir, grid_filename))

            print(f"Saved {grid_filename}")

process_images('./dataset', './dataset_result_grids', get_nude)