| | |
| | 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) |
| | |
| | |
| | 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") |
| | |
| | |
| | num_pages = (total_images + images_per_page - 1) // images_per_page |
| | |
| | for page_num in range(num_pages): |
| | |
| | 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] |
| | |
| | |
| | fig, axes = plt.subplots(grid_size[0], grid_size[1], figsize=(20, 20)) |
| | |
| | |
| | manager = plt.get_current_fig_manager() |
| | try: |
| | |
| | if hasattr(manager, 'window'): |
| | if hasattr(manager.window, 'showMaximized'): |
| | manager.window.showMaximized() |
| | elif hasattr(manager, 'full_screen_toggle'): |
| | manager.full_screen_toggle() |
| | else: |
| | |
| | fig.set_size_inches(19.2, 10.8) |
| | except: |
| | pass |
| | |
| | |
| | axes_flat = axes.flatten() |
| | |
| | |
| | for idx, (ax, img_path) in enumerate(zip(axes_flat, page_images)): |
| | try: |
| | img = mpimg.imread(img_path) |
| | ax.imshow(img) |
| | |
| | filename = img_path.name |
| | |
| | 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') |
| | |
| | |
| | for idx in range(len(page_images), images_per_page): |
| | axes_flat[idx].axis('off') |
| | |
| | |
| | fig.suptitle(f'Page {page_num + 1}/{num_pages} (Images {start_idx + 1}-{end_idx}/{total_images})', |
| | fontsize=14, fontweight='bold') |
| | |
| | |
| | plt.tight_layout(rect=[0, 0, 1, 0.96]) |
| | |
| | |
| | plt.show() |
| | |
| | print(f"Displayed page {page_num + 1}/{num_pages}") |
| | |
| | |
| | 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__": |
| | |
| | image_directory = "min_max_segments" |
| | |
| | |
| | display_images_grid(image_directory, images_per_page=100, grid_size=(10, 10)) |