|
|
|
""" |
|
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) |
|
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: |
|
|
|
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) |
|
|