Skip to main content

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

Project description

im2im: Automatically Converting In-Memory Image Representations


PyPI - Version PyPI - Python Version Downloads Tests codecov

The im2im python package provides an automated approach for converting in-memory image representations across a variety of image processing libraries, including scikit-image, opencv-python, scipy, PIL, numpy, PyTorch, 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.

Usage

im2im is developed to simplify image type conversions in Visual Programming Systems (VPS) for image processing. It removes the need for manual conversion steps, significantly improving accessibility—especially for non-expert users.

Installation (At Execution Environment)

Install the package via pip:

pip install im2im

Or install the package directly from GitHub:

pip install git+https://github.com/c3di/im2im.git

Usage for Auto Type Conversion

API Entry Point: im2im

import numpy as np
from im2im import Image, im2im

# Example input: an image that is a numpy.ndarray with shape (20, 20, 3) in uint8 format
to_be_converted = Image(np.random.randint(0, 256, (20, 20, 3), dtype=np.uint8), "numpy.rgb_uint8")
# Convert to the target image with metadata preset "torch.gpu".
converted: Image = im2im(to_be_converted, "torch.gpu")

Metadata presets are defined in src/im2im/find_metadata_builtin_preset.py.

For additional APIs such as im2im_code, please refer to src/im2im/api.py.

Integration in Visual Programming Systems:

Take the Blockly visual programming framework as an example. To enable automatic type conversion:

  • Call im2im() before operations to convert the input.
  • Explicitly set the metadata for the output image.

Without im2im

Blockly.Python.forBlock['gaussian_blur'] = function (block) {
  requiredImports.add("from skimage.filters import gaussian");
  // inputs
  var image = Blockly.Python.valueToCode(block, "IMAGE", Blockly.Python.ORDER_NONE) || "None";
  var sigma = block.getFieldValue("SIGMA") || "0.5";
  var resultVar = Blockly.Python.nameDB_.getDistinctName("out_im", Blockly.VARIABLE_CATEGORY_NAME);
  // code without im2im
  var code = `${resultVar} = gaussian(${image}, sigma=${sigma})`;
  // output
  Blockly.Python.definitions_["define_" + resultVar] = code;
  return [`${resultVar}`, Blockly.Python.ORDER_NONE];
};

With im2im

Blockly.Python.forBlock['gaussian_blur'] = function (block) {
  // inputs as above ...
  // code with im2im
  var convert_to = `in_im1 = im2im(${image}, 'skimage.before_gaussian')`;
  var operation = `e_gaussian_filtered = gaussian(in_im1.raw_image, sigma=${sigma})`;
  var convert_back = `${resultVar} = Image(e_gaussian_filtered, {**in_im1.metadata, 'image_data_type': 'float64(0to1)'})`;
  var code = `${convert_to}\n${operation}\n${convert_back}`;
  // outputs as above...
};

For additional implementation examples, see the comparative_analysis/1/enhanced_VPL4IP.html and comparative_analysis/2/enhanced_VPL4IP.html .

Note: For detailed comparisons between visual programming systems (visual interface and execution) with and without im2im, refer to the following studies: Open in Colab, Open in Colab.

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

im2im: Automatically Converting In-Memory Image Representations using A Knowledge Graph Approach

accepted for publication in OOPSLA 2025.

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.6.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

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

im2im-0.0.6-py3-none-any.whl (135.7 kB view details)

Uploaded Python 3

File details

Details for the file im2im-0.0.6.tar.gz.

File metadata

  • Download URL: im2im-0.0.6.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for im2im-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f30e2717632d19514fa46cd5e2962ecfbb99b29ac1b7b21488a37630212b75ea
MD5 1bf3a9ea1e6a4d7dcaff8e421a01da01
BLAKE2b-256 4b3264ec055df500f72226fb1e246fdfa3248b7d33d33976a89abb0cb5d62314

See more details on using hashes here.

File details

Details for the file im2im-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: im2im-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 135.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for im2im-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1e53716c51fad5f9e59dccaa4d0a99ee8a9a30c51f59c25e644ddc453ecf8ac2
MD5 0b39f883c03beee3f0b83fdf8216d8b6
BLAKE2b-256 559144cdcc2d49c525945bd0cb8938564023a94372db40c08341771363b74d98

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