Skip to content

DIM-Corp/i2g

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖼️ 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

About

Image to Graph Converter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages