Skip to main content

jpg-dwg

Convert scanned P&ID (Piping and Instrumentation) drawing images to DXF (lines only), and optionally to DWG via an external converter.

Install

From PyPI (recommended):

pip install jpg-dwg

From source:

git clone https://github.com/Nisanth-sr/image-dwg.git
cd jpg-dwg
pip install -e .

Or install dependencies only and run as module:

pip install -r requirements.txt
python -m jpg_dwg input.png -o output.dxf

Usage

# Basic: image → DXF (after pip install jpg-dwg)
jpg-dwg scan.png -o drawing.dxf

# Or as module
python -m jpg_dwg scan.png -o drawing.dxf

# With options (invert is on by default for black-on-white P&ID; use --no-invert if needed)
python -m jpg_dwg scan.png -o drawing.dxf --preview preprocessed.png --scale 0.1

# Enable P&ID symbol detection (contour-based heuristics)
python -m jpg_dwg scan.png -o drawing.dxf --symbols

# Also produce DWG (requires ODA File Converter)
python -m jpg_dwg scan.png -o drawing.dxf --dwg drawing.dwg

Options

Option Description
input Input image path (PNG, JPG, etc.)
-o, --output Output DXF path
--scale Drawing units per pixel (default 1.0)
--dpi DPI hint (default 300)
--no-deskew Disable automatic deskew
--invert Invert binary (default: on for black lines on white)
--no-invert Do not invert (for white lines on dark scan)
--adaptive Use adaptive threshold instead of Otsu
--no-denoise Disable morphology denoise
--thin Thinning/skeletonization (requires opencv-contrib)
--preview PATH Save preprocessed binary image
--symbols Run P&ID symbol detection and insert blocks
--dwg PATH Also convert DXF to DWG (see below)
-v, --verbose Verbose logging

DWG output

This tool writes DXF only. To get DWG:

  1. Install ODA File Converter.
  2. Set ODA_FILE_CONVERTER to the converter executable path, or ensure it is on PATH.
  3. Use --dwg output.dwg. The CLI will run the converter after writing the DXF.

Limitations

  • Quality depends on scan resolution and contrast. Preprocess with --invert or --preview to tune.
  • Vectorization extracts lines only (OpenCV Hough).
  • P&ID symbol detection is heuristic (contour-based). For production, consider a trained model (e.g. YOLO on P&ID symbols).

Publishing to PyPI (maintainers)

To avoid distributing source code, build and upload only a bytecode-only wheel (no .py files, no sdist).

  1. Create an account and API token at pypi.org (use test.pypi.org for testing).
  2. From the repo root:
    pip install build twine
    python scripts/build_bytecode_wheel.py
    twine upload dist/*.whl
    
    • build_bytecode_wheel.py builds a wheel, then repacks it so the package contains only .pyc (no .py source). The resulting wheel in dist/ is suitable for upload.
    • Upload only the wheel (dist/*.whl); do not run python -m build and do not upload dist/*.tar.gz (sdist), so source is not published.
  3. When prompted: username __token__, password = your PyPI API token.
  4. To test first: twine upload --repository testpypi dist/*.whl, then pip install -i https://test.pypi.org/simple/ jpg-dwg.

Note: The bytecode-only wheel is built for the Python version that runs the script (e.g. 3.11). To support multiple versions, run scripts/build_bytecode_wheel.py under each desired Python (e.g. 3.9, 3.10, 3.11, 3.12) and upload all resulting wheels.

Update version in pyproject.toml and the [project.urls] Homepage/Source to your repo before publishing.

Project layout

jpg-dwg/
├── pyproject.toml
├── requirements.txt
├── README.md
├── scripts/
│   └── build_bytecode_wheel.py   # Build wheel with only .pyc (no source)
├── src/jpg_dwg/
│   ├── cli.py
│   ├── preprocess.py
│   ├── vectorize.py
│   ├── export_dxf.py
│   ├── symbols.py
│   └── config.py
└── tests/

Metadata

Release files for jpg-dwg 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for jpg-dwg 0.1.2
File Interpreter ABI Platform Actions
jpg_dwg-0.1.2-py3-none-any.whl Python 3 none any Details for jpg_dwg-0.1.2-py3-none-any.whl

Release files / jpg_dwg-0.1.2-py3-none-any.whl

Download URL jpg_dwg-0.1.2-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2bb82f1f8dcfe926a167a0e3c57c0adf6cbcb1946ce7e8677b2c9309d4b907d
BLAKE2b-256 checksum
How to use checksums
3974777c1c78fd62eefab9c5d36115d02fbefb507c7cd8f798f688877dd5eb63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for jpg-dwg 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page