sign_language_comparison_table_modified / display_min_max_grid.py
HowardZhangdqs's picture
Add files using upload-large-folder tool
a98fc5a verified
#!/usr/bin/env python3
import os
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from pathlib import Path
import numpy as np
def display_images_grid(image_dir, images_per_page=100, grid_size=(10, 10)):
"""
Display images in a grid format, 100 images per page (10x10)
"""
image_dir = Path(image_dir)
# Get all PNG files and sort them
image_files = sorted(list(image_dir.glob('*.png')))
if not image_files:
print(f"No PNG files found in {image_dir}")
return
total_images = len(image_files)
print(f"Found {total_images} images")
# Calculate number of pages
num_pages = (total_images + images_per_page - 1) // images_per_page
for page_num in range(num_pages):
# Calculate start and end indices for this page
start_idx = page_num * images_per_page
end_idx = min(start_idx + images_per_page, total_images)
page_images = image_files[start_idx:end_idx]
# Create figure with subplots
fig, axes = plt.subplots(grid_size[0], grid_size[1], figsize=(20, 20))
# Make the window fullscreen
manager = plt.get_current_fig_manager()
try:
# Try different methods for fullscreen depending on backend
if hasattr(manager, 'window'):
if hasattr(manager.window, 'showMaximized'):
manager.window.showMaximized()
elif hasattr(manager, 'full_screen_toggle'):
manager.full_screen_toggle()
else:
# Fallback to maximize window
fig.set_size_inches(19.2, 10.8) # Typical 1920x1080 screen
except:
pass
# Flatten axes array for easier iteration
axes_flat = axes.flatten()
# Display each image
for idx, (ax, img_path) in enumerate(zip(axes_flat, page_images)):
try:
img = mpimg.imread(img_path)
ax.imshow(img)
# Extract filename without path for title
filename = img_path.name
# Truncate filename if too long
if len(filename) > 20:
filename = filename[:17] + '...'
ax.set_title(filename, fontsize=8, pad=2)
ax.axis('off')
except Exception as e:
print(f"Error loading {img_path}: {e}")
ax.axis('off')
# Hide remaining empty subplots
for idx in range(len(page_images), images_per_page):
axes_flat[idx].axis('off')
# Set overall title
fig.suptitle(f'Page {page_num + 1}/{num_pages} (Images {start_idx + 1}-{end_idx}/{total_images})',
fontsize=14, fontweight='bold')
# Adjust layout to prevent overlap
plt.tight_layout(rect=[0, 0, 1, 0.96])
# Show the plot
plt.show()
print(f"Displayed page {page_num + 1}/{num_pages}")
# Ask if user wants to continue to next page (except for last page)
if page_num < num_pages - 1:
response = input("Press Enter to continue to next page, or 'q' to quit: ")
if response.lower() == 'q':
break
print("Display complete!")
if __name__ == "__main__":
# Directory containing the images
image_directory = "min_max_segments"
# Display images in 10x10 grid, 100 per page
display_images_grid(image_directory, images_per_page=100, grid_size=(10, 10))