i2g — Image to Graph Converter
Convert grayscale images into graph structures using NetworkX. Each pixel becomes a node connected to its neighbors (4- or 8-connectivity), with pixel intensity stored as a node attribute.
Installation
pip install i2g
Or install from source in editable mode:
git clone https://github.com/DIM-Corp/i2g.git
cd i2g
pip install -e .[dev]
Requires Python 3.10+. Dependencies: numpy, Pillow, networkx.
Usage
from i2g import ImageGraphConverter
converter = ImageGraphConverter("my_image.png", connectivity="8")
graph, img_array = converter.convert()
shape = converter.shape() # (height, width)
num_nodes, num_edges = converter.info()
print(f"Image shape: {shape}")
print(f"Graph has {num_nodes} nodes and {num_edges} edges.")
Node attributes
Each node is keyed by (row, col) and carries two attributes:
| Attribute | Type | Description |
|---|---|---|
intensity |
int |
Grayscale pixel value (0–255) |
pos |
tuple[int, int] |
(col, -row) — ready for matplotlib/networkx plotting |
Connectivity
| Value | Neighbors |
|---|---|
"4" |
Up, down, left, right |
"8" (default) |
Cardinal + diagonal (8 neighbors) |
Error handling
| Situation | Exception raised |
|---|---|
Invalid connectivity value |
ValueError at construction time |
| Image file not found | FileNotFoundError from convert() |
| File exists but is not a valid image | OSError from convert() |
| Image exceeds 10 million pixels | ValueError from convert() |
shape() or info() called before convert() |
RuntimeError |
Running tests
pytest
License
MIT License — see LICENSE for details.
Contact
Metadata
Release files for i2g 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| i2g-0.2.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| i2g-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / i2g-0.2.0.tar.gz
| Download URL | i2g-0.2.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b648b5943962066351ce3926030c61ce19744bffcafbca036069110f4b191e29
|
|
BLAKE2b-256 checksum How to use checksums |
e39a23da23c4d9ee99fa38bb27cbe3e59f0e5af7dedc0332fc220d693e616fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / i2g-0.2.0-py3-none-any.whl
| Download URL | i2g-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
008cc8eb5cf1780c85f9c7dd0ac24bdea3835b497c09adac205a6e8eaafcd32f
|
|
BLAKE2b-256 checksum How to use checksums |
0eb81697e5073307996d6e278d6017e2285b23e954a45bb88b6cb53b7b05a599
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|