How cmwaseemyousef/pid-pipe-removal works
File structure
• Top-level scripts each implement one stage of the pipeline:
• preprocess.py – initial image cleanup (e.g., resizing, denoising)
• generate_mask.py – computes a binary pipe mask via grayscale differencing & thresholding
• detect_symbols.py – (optional) identifies and protects critical symbols
• remove_pipes.py / remove_pipes_final.py – applies inpainting to remove pipes
• generate_pipe_free_output.py – orchestrates the full pipeline end-to-end
• train_unet.py – an abandoned U-Net–based approach
• Two data folders:
• data/ – holds input.jpg, nearest_expected_output.jpg, final_output.jpg
• results/ – holds intermediate previews such as mask_preview.png
README for additional insights
• Confirms a linear, five-step pipeline: load images → grayscale diff → mask generation (threshold + dilation) → inpainting → save outputs.
• No external services or databases—entirely local processing in Python.
a. Main components:
1. Input Module
• Reads original P&ID (image or PDF)
• Script: convert_pdf.py (if starting from PDF) or direct image load
2. Preprocessing Module
• Normalizes image (resize, denoise)
• Script: preprocess.py
3. Mask Generation Module
• Computes cv2.absdiff between original and reference
• Applies threshold + morphological dilation
• Script: generate_mask.py
4. Symbol Detection Module (optional)
• Identifies and protects valves, sensors, labels
• Script: detect_symbols.py
5. Inpainting Module
• Uses cv2.inpaint with the binary mask to remove pipes
• Scripts: remove_pipes.py & remove_pipes_final.py
6. Orchestrator / Runner
• Ties all stages together end-to-end
• Script: generate_pipe_free_output.py
7. Output Module
• Writes final cleaned P&ID to data/final_output.jpg
• Saves results/mask_preview.png
b. Relationships and interactions:
• Data flows strictly left→right through the six processing stages.
• Preprocessing outputs feed into mask generation; mask feeds into inpainting; final is written to disk.
• The orchestrator module imports and invokes each stage in sequence.
c. Architectural patterns / design principles:
• Linear batch pipeline: single-pass ETL style
• Single responsibility: each script handles one logical step
• Modular design: easy to swap out mask generation (e.g., U-Net) or symbol detection
d. Key technologies & libraries:
• Python 3.x
• OpenCV (cv2.absdiff, threshold, dilation, inpaint)
• NumPy (array ops)
• Google Colab (dev environment, optional)