Skip to main content

Automatically converting in-memory representations of images using a knowledge graph of type description.

Project description

im2im

PyPI - Version PyPI - Python Version Documentation Tests codecov

The im2im package provides an automated approach for converting in-memory image representations across a variety of image processing libraries, including numpy, opencv-python, torch, PIL, Matplotlib.plt.imshow, and Tensorflow. It handles the nuances inherent to each library's image representation, such as data formats (numpy arrays, PIL images, torch tensors, and so on), color channel (RGB or grayscale), channel order (channel first or last or none), device (CPU/GPU), and pixel intensity ranges.

At the core of the package is a knowledge graph, where each node encapsulates metadata detailing an image representation, and the edges between nodes represent code snippets for converting images from one representation to another. When converting from the source to the target, the im2im package identifies the shortest path within the graph, it gathers all relevant conversion snippets encountered along the path. These snippets are then combined to formulate the final conversion code, which is subsequently employed to transform the source images into the desired target format.

Installation

Install the package via pip:

pip install im2im

Usage

One example from the image data in numpy to the image data in PyTorch:

import numpy as np
from im2im import im2im

source = np.random.randint(0, 256, (20, 20, 3), dtype=np.uint8)
target = im2im(source, {"lib": "numpy"}, {"lib": "torch", "color_channel":"gray", "image_dtype": "uint8"})

For other APIs like im2im_code, and im2im_path, please refer to tutorials or public APIs.

Knowledge Graph Extension

Our package is designed for easy knowledge graph extension. Once you are familiar with the mechanisms behind the construction of the knowledge graph, you can leverage a suite of functions designed for various extension requirements including add_meta_values_for_image, add_edge_factory_cluster, and add_conversion_for_metadata_pairs, each tailored for different extension needs.

Evaluation

Accuracy

All primitive conversion code snippets are stored within the edges of the knowledge graph. These snippets are verified through execution checks to guarantee their correctness. For a more in-depth examination, please refer to the test_conversion_code_in_kg.py.

Performance profiling

The performance of knowledge graph construction and code generation processes is meticulously analyzed using the cProfile module. For comprehensive insights, please refer to the profiling notebooks.

Usability Evaluation

Please refer to Usability Evaluation.

Contribution

We welcome all contributions to this project! If you have suggestions, feature requests, or want to contribute in any other way, please feel free to open an issue or submit a pull request.

For detailed instructions on developing, building, and publishing this package, please refer to the README_DEV.

Cite

if you use our tool or code in your research, please cite the following paper:

Todo

License

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

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

im2im-0.0.3.tar.gz (230.0 kB view hashes)

Uploaded Source

Built Distribution

im2im-0.0.3-py3-none-any.whl (82.7 kB view hashes)

Uploaded Python 3

Supported by

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