File size: 3,584 Bytes
a98fc5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/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))