Spaces:
Runtime error
Runtime error
Delete src/make_image_grid.py
Browse files- src/make_image_grid.py +0 -57
src/make_image_grid.py
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
from PIL import Image
|
2 |
-
import os
|
3 |
-
import re
|
4 |
-
import tqdm
|
5 |
-
|
6 |
-
|
7 |
-
def create_grid(directory, save_path=None):
|
8 |
-
# Get list of image files in the directory
|
9 |
-
files = sorted([f for f in os.listdir(directory) if f.endswith('.png')])
|
10 |
-
|
11 |
-
# Assuming all images are the same size
|
12 |
-
img_sample = Image.open(os.path.join(directory, files[0]))
|
13 |
-
width, height = img_sample.size
|
14 |
-
|
15 |
-
# Calculate grid dimensions for 24 images
|
16 |
-
grid_width = width * 6 # 6 images in each row
|
17 |
-
grid_height = height * 4 # 4 rows
|
18 |
-
|
19 |
-
# Create new image for the grid
|
20 |
-
grid_img = Image.new('RGB', (grid_width, grid_height))
|
21 |
-
|
22 |
-
for idx, file in enumerate(files):
|
23 |
-
img = Image.open(os.path.join(directory, file))
|
24 |
-
x = idx % 6 * width # 6 images in each row
|
25 |
-
y = idx // 6 * height # 4 rows
|
26 |
-
grid_img.paste(img, (x, y))
|
27 |
-
|
28 |
-
if save_path:
|
29 |
-
grid_img.save(f'{save_path}/{directory.split("/")[-1]}_grid.png')
|
30 |
-
else:
|
31 |
-
grid_img.save(f'{directory}_grid.png')
|
32 |
-
|
33 |
-
|
34 |
-
def list_subdirectories(parent_directory):
|
35 |
-
# Regex pattern to match the subdirectory naming convention
|
36 |
-
pattern = re.compile(r"\d+_of_\d+_masked1")
|
37 |
-
|
38 |
-
# List all subdirectories
|
39 |
-
subdirs = [d for d in os.listdir(parent_directory) if os.path.isdir(os.path.join(parent_directory, d))]
|
40 |
-
|
41 |
-
# Filter subdirectories based on naming convention
|
42 |
-
matching_subdirs = [d for d in subdirs if pattern.match(d)]
|
43 |
-
|
44 |
-
return matching_subdirs
|
45 |
-
|
46 |
-
# List of directories
|
47 |
-
|
48 |
-
# for prompt in ["A cat walking in a park", "A dog running in a park", " A wooden barrel drifting on a river", "A kite flying in the sky"]:
|
49 |
-
# for prompt in ["A car driving on the road"]:
|
50 |
-
# try:
|
51 |
-
# directories = list_subdirectories(f"demo4/video41-att_mask/{prompt}")
|
52 |
-
# except FileNotFoundError:
|
53 |
-
# print(f"Directory not found: {prompt}")
|
54 |
-
# continue
|
55 |
-
# os.makedirs(f"demo4/{prompt}/consolidated_grids", exist_ok=True)
|
56 |
-
# for directory in tqdm.tqdm(directories):
|
57 |
-
# create_grid(os.path.join(f"demo4/video41-att_mask/{prompt}", directory), save_path=f"demo4/{prompt}/consolidated_grids")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|