Skip to main content

Convert images to graphs

Project description

🖼️ i2g — Image to Graph Converter

Python License: MIT PyPI - Status Tests

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 feature.


🚀 Features

  • ✅ Convert any grayscale image into a networkx graph.
  • ✅ Choose 4- or 8-neighborhood connectivity.
  • ✅ Each node stores:
    • intensity: pixel grayscale value (0-255)
    • pos: (x, y) coordinate for plotting.
  • ✅ Easily query the graph’s shape, number of nodes, and edges.

🛠️ Installation

Clone this repository and install in editable mode:

git clone https://github.com/DIM-Corp/i2g.git
cd i2g
pip install -e .

Requires: numpy, pillow, networkx.


✍️ Example usage

from i2g import ImageGraphConverter

# Create a converter for your image
converter = ImageGraphConverter("my_image.png", connectivity='8')

# Convert the image to a graph
graph, img_array = converter.convert()

# Query information
shape = converter.shape()  # returns (height, width)
num_nodes, num_edges = converter.info()

print(f"Image shape: {shape}")
print(f"Graph has {num_nodes} nodes and {num_edges} edges.")

🚀 Running tests

This project uses pytest.

Run the tests with:

pytest

📄 License

This project is licensed under the MIT License.
See the LICENSE file for details.


💪 Contributing

Pull requests are welcome!
For major changes, please open an issue first to discuss what you’d like to change.


⭐ Acknowledgements

⭐ Contacts

info@dimcorp237.com mdieffi@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i2g-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

i2g-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file i2g-0.1.0.tar.gz.

File metadata

  • Download URL: i2g-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for i2g-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5cc3530bd2732663e51a0c86e5cc891634ac32f846a1f99c4f0f870c6b760b42
MD5 7be50f99dbc5edc6180b1d39a9bafa6e
BLAKE2b-256 3a7942ff0626c54299ba7bd3f74284d1b2646188ca9066c3b70214fdb4d864ae

See more details on using hashes here.

File details

Details for the file i2g-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: i2g-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for i2g-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e0f5974319c9a79fdf62869b5f841b59be3af8a11da48a51adf18afe711f31c
MD5 20795e4f043005af48eea6d510950127
BLAKE2b-256 c00fc2de9d41412e99c17cf069c6ac23e3f007a4c4420b1c090d488a7f1e376f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page