Skip to content

Commit 21b204f

Browse files
committed
change ""
1 parent b1a0bd5 commit 21b204f

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

create_alpha_patchwork.py

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_images_from_dir(dir_path, max_images=25):
3636
"""Get up to max_images PNG files from a directory."""
3737
images = []
3838
for file in sorted(os.listdir(dir_path)):
39-
if file.endswith('.png'):
39+
if file.endswith(".png"):
4040
images.append(os.path.join(dir_path, file))
4141
if len(images) >= max_images:
4242
break
@@ -53,12 +53,12 @@ def create_grid_from_images(image_paths, grid_size=5):
5353
img_width, img_height = first_img.size
5454

5555
# Create a blank canvas for the grid
56-
grid_img = Image.new('RGB',
57-
(img_width * grid_size, img_height * grid_size),
58-
color='black')
56+
grid_img = Image.new(
57+
"RGB", (img_width * grid_size, img_height * grid_size), color="black"
58+
)
5959

6060
# Place images in grid
61-
for idx, img_path in enumerate(image_paths[:grid_size * grid_size]):
61+
for idx, img_path in enumerate(image_paths[: grid_size * grid_size]):
6262
if idx >= grid_size * grid_size:
6363
break
6464

@@ -73,42 +73,44 @@ def create_grid_from_images(image_paths, grid_size=5):
7373

7474
@click.command()
7575
@click.option(
76-
'--input-dir',
76+
"--input-dir",
7777
type=click.Path(exists=True),
7878
required=True,
79-
help='Directory containing alpha_* subdirectories with generated images'
79+
help="Directory containing alpha_* subdirectories with generated images",
8080
)
8181
@click.option(
82-
'--output-path',
82+
"--output-path",
8383
type=click.Path(),
8484
required=True,
85-
help='Output path for the patchwork image'
85+
help="Output path for the patchwork image",
8686
)
8787
@click.option(
88-
'--images-per-alpha',
88+
"--images-per-alpha",
8989
type=int,
9090
default=25,
91-
help='Number of images to sample per alpha value (default: 25)'
91+
help="Number of images to sample per alpha value (default: 25)",
9292
)
9393
@click.option(
94-
'--grid-size',
94+
"--grid-size",
9595
type=int,
9696
default=5,
97-
help='Size of the grid for each alpha patch (default: 5x5)'
97+
help="Size of the grid for each alpha patch (default: 5x5)",
9898
)
9999
@click.option(
100-
'--max-alphas',
100+
"--max-alphas",
101101
type=int,
102102
default=25,
103-
help='Maximum number of alpha values to include (default: 25)'
103+
help="Maximum number of alpha values to include (default: 25)",
104104
)
105105
@click.option(
106-
'--patchwork-cols',
106+
"--patchwork-cols",
107107
type=int,
108108
default=5,
109-
help='Number of columns in the main patchwork grid (default: 5)'
109+
help="Number of columns in the main patchwork grid (default: 5)",
110110
)
111-
def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_alphas, patchwork_cols):
111+
def create_patchwork(
112+
input_dir, output_path, images_per_alpha, grid_size, max_alphas, patchwork_cols
113+
):
112114
"""Create a patchwork visualization of images across different alpha values."""
113115

114116
print(f"Scanning directory: {input_dir}")
@@ -135,7 +137,9 @@ def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_al
135137
image_paths = get_images_from_dir(alpha_path, max_images=images_per_alpha)
136138

137139
if len(image_paths) < images_per_alpha:
138-
print(f" Warning: Only found {len(image_paths)} images (expected {images_per_alpha})")
140+
print(
141+
f" Warning: Only found {len(image_paths)} images (expected {images_per_alpha})"
142+
)
139143

140144
if not image_paths:
141145
print(f" Skipping alpha={alpha_value} (no images found)")
@@ -146,7 +150,9 @@ def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_al
146150
if grid:
147151
alpha_grids.append(grid)
148152
alpha_values.append(alpha_value)
149-
print(f" Created {grid_size}x{grid_size} grid with {len(image_paths)} images")
153+
print(
154+
f" Created {grid_size}x{grid_size} grid with {len(image_paths)} images"
155+
)
150156

151157
if not alpha_grids:
152158
print("No grids created. Exiting.")
@@ -164,8 +170,9 @@ def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_al
164170
fig_width = patchwork_cols * 4
165171
fig_height = patchwork_rows * 4
166172

167-
fig, axes = plt.subplots(patchwork_rows, patchwork_cols,
168-
figsize=(fig_width, fig_height))
173+
fig, axes = plt.subplots(
174+
patchwork_rows, patchwork_cols, figsize=(fig_width, fig_height)
175+
)
169176

170177
# Handle case where there's only one row or column
171178
if patchwork_rows == 1 and patchwork_cols == 1:
@@ -182,22 +189,26 @@ def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_al
182189

183190
ax = axes[row, col]
184191
ax.imshow(grid)
185-
ax.set_title(f'α = {alpha_val}', fontsize=14, fontweight='bold')
186-
ax.axis('off')
192+
ax.set_title(f"α = {alpha_val}", fontsize=14, fontweight="bold")
193+
ax.axis("off")
187194

188195
# Hide unused subplots
189196
for idx in range(len(alpha_grids), patchwork_rows * patchwork_cols):
190197
row = idx // patchwork_cols
191198
col = idx % patchwork_cols
192-
axes[row, col].axis('off')
193-
194-
plt.suptitle(f'Alpha Value Patchwork ({grid_size}×{grid_size} images per alpha)',
195-
fontsize=16, fontweight='bold', y=0.995)
199+
axes[row, col].axis("off")
200+
201+
plt.suptitle(
202+
f"Alpha Value Patchwork ({grid_size}×{grid_size} images per alpha)",
203+
fontsize=16,
204+
fontweight="bold",
205+
y=0.995,
206+
)
196207
plt.tight_layout()
197208

198209
# Save the figure
199210
print(f"Saving patchwork to: {output_path}")
200-
plt.savefig(output_path, dpi=150, bbox_inches='tight')
211+
plt.savefig(output_path, dpi=150, bbox_inches="tight")
201212
plt.close()
202213

203214
print(f"✓ Patchwork created successfully!")
@@ -206,5 +217,5 @@ def create_patchwork(input_dir, output_path, images_per_alpha, grid_size, max_al
206217
print(f" - {patchwork_rows}×{patchwork_cols} patchwork grid")
207218

208219

209-
if __name__ == '__main__':
220+
if __name__ == "__main__":
210221
create_patchwork()

0 commit comments

Comments
 (0)