File size: 1,894 Bytes
d53674a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

"""
Count images and summarize resolutions for Innodisk PCB dataset.

Usage:
    python count_pcb_images.py /path/to/Innodisk_PCB_datasets
"""

import sys
from pathlib import Path
from collections import defaultdict
from PIL import Image

IMAGE_EXTS = {'.jpg', '.jpeg', '.png', '.bmp', '.tif', '.tiff'}

def scan_dataset(root: Path):
    splits = defaultdict(list)  # split_name -> list[Path]
    for p in root.glob('*'):
        if not p.is_dir():
            continue
        name = p.name.lower()
        if name.startswith('train'):
            split = 'train'
        elif name.startswith('test'):
            split = 'test'
        elif name.startswith('val'):
            split = 'val'
        else:
            # unknown folder, skip
            continue
        for img in p.rglob('*'):
            if img.suffix.lower() in IMAGE_EXTS:
                splits[split].append(img)
    return splits

def summarize(splits):
    print("\n===== Image Counts =====")
    for split, files in splits.items():
        print(f"{split.capitalize():5s}: {len(files):,} images")
    print("\n===== Resolution Stats =====")
    for split, files in splits.items():
        res_counter = defaultdict(int)
        for img_path in files:
            try:
                with Image.open(img_path) as im:
                    res_counter[im.size] += 1
            except Exception:
                continue
        print(f"\n[{split.capitalize()}]")
        for (w, h), cnt in sorted(res_counter.items(), key=lambda x: (-x[1], x[0])):
            print(f"{w}×{h}: {cnt:,}")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python count_pcb_images.py /path/to/Innodisk_PCB_datasets")
        sys.exit(1)
    root = Path(sys.argv[1])
    if not root.exists():
        print("Path does not exist:", root)
        sys.exit(1)
    splits = scan_dataset(root)
    summarize(splits)