88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import random
|
|
import subprocess
|
|
from pathlib import Path
|
|
import shutil
|
|
|
|
def run_command(cmd):
|
|
print(f"Running: {' '.join(cmd)}")
|
|
subprocess.run(cmd, check=True)
|
|
|
|
def main():
|
|
# Setup paths
|
|
base_dir = Path(__file__).parent
|
|
img_dir = base_dir / "ICCAD2019" / "img"
|
|
out_dir = base_dir / "out" / "debug1"
|
|
|
|
if out_dir.exists():
|
|
shutil.rmtree(out_dir)
|
|
out_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Get images
|
|
all_images = list(img_dir.glob("*.png"))
|
|
if not all_images:
|
|
print("No images found in ICCAD2019/img")
|
|
return
|
|
|
|
selected_images = random.sample(all_images, min(5, len(all_images)))
|
|
|
|
print(f"Selected {len(selected_images)} images for debugging.")
|
|
|
|
for img_path in selected_images:
|
|
print(f"\nProcessing {img_path.name}...")
|
|
case_dir = out_dir / img_path.stem
|
|
case_dir.mkdir(exist_ok=True)
|
|
|
|
# 1. Skeleton Extraction
|
|
# Note: The user mentioned "black background, white subject" or vice versa.
|
|
# The script has --invert. I'll try without invert first, assuming standard layout (often drawn dark on light or light on dark).
|
|
# Let's check one image first? No, I'll just run it.
|
|
# Actually, usually layouts are drawn objects. If background is black, objects are white.
|
|
# My script assumes objects are white (value 1) for skeletonization.
|
|
# If the image is white background, I need to invert.
|
|
# I'll try both or just assume one. Let's assume we might need --invert if it's white background.
|
|
# I'll run with --invert if the mean pixel value is high (white background).
|
|
|
|
# But wait, I can't easily check mean here without loading.
|
|
# I'll just run the extraction script.
|
|
|
|
extract_cmd = [
|
|
"python3", "scripts/skeleton_extract.py",
|
|
str(img_path),
|
|
str(case_dir),
|
|
"--denoise", "3"
|
|
]
|
|
# Heuristic: if filename contains 'nonhotspot', it might be a clip.
|
|
# Let's just try running it.
|
|
run_command(extract_cmd)
|
|
|
|
sk_png = case_dir / (img_path.stem + "_sk.png")
|
|
if not sk_png.exists():
|
|
print(f"Failed to generate skeleton for {img_path.name}")
|
|
continue
|
|
|
|
# 2. Vectorization
|
|
vec_json = case_dir / (img_path.stem + "_vec.json")
|
|
vec_cmd = [
|
|
"python3", "scripts/vectorize_skeleton.py",
|
|
str(sk_png),
|
|
str(vec_json)
|
|
]
|
|
run_command(vec_cmd)
|
|
|
|
# 3. Expansion (Reconstruction)
|
|
recon_png = case_dir / (img_path.stem + "_recon.png")
|
|
expand_cmd = [
|
|
"python3", "scripts/expand_skeleton.py",
|
|
str(vec_json),
|
|
str(recon_png),
|
|
"--line-width", "3" # Adjust as needed
|
|
]
|
|
run_command(expand_cmd)
|
|
|
|
print(f"\nDebug run complete. Check results in {out_dir}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|