Skip to main content

Image IO Interfaces for wide range image formats (jpg, png, tif, dng, yuv and RAWs), with Exif support, interact nicely with numpy array.

Project description

CXX Image IO

CXX Image IO is a Python project which provides the image IO interfaces, binding with the C++ library: https://github.com/emmcb/cxx-image, These IO interfaces are designed to read and write images in many file formats in generic way and to interact nicely with numpy array.

Image format Read Write EXIF Pixel precision Pixel type File extension
BMP x x 8 bits Grayscale, RGB, RGBA .bmp
CFA x x 16 bits Bayer .cfa
DNG x x x 16 bits, float Bayer, RGB .dng
JPEG x x x 8 bits Grayscale, RGB .jpg, .jpeg
MIPIRAW x x 10 bits, 12 bits Bayer .RAWMIPI, .RAWMIPI10, .RAWMIPI12
PLAIN x x * * .plain16, .nv12, *
PNG x x 8 bits, 16 bits Grayscale, RGB, RGBA .png
TIFF x x x 8 bits, 16 bits, float Bayer, RGB .tif, .tiff

Getting Started

Prerequisites

  • numpy >= 2.1.0
  • ninja >= 1.11.1

This projet currently supports Python from 3.10 to 3.13 on

  • Windows: x86_64
  • Linux: x86_64 and aarch64, glibc 2.28+
  • MacOS: x86_64 and arm64, 11.0+

Installation

The python package cxx-image-io is to be installed by pip

pip install cxx-image-io

Usage example

Image reading

read_image is able to read a image file and return a numpy array and ImageMetadata object.

from cxx_image_io import read_image
from cxx_image_io import ImageMetadata
import numpy as np
from pathlib import Path

image, metadata = read_image(Path('/path/to/image.jpg'))
assert isinstance(image, np.ndarray)

print('Type:', image.dtype)
print('Shape:', image.shape)

image is a numpy array which is suitable for the image processing afterwards.

The result could be like this:

Type: uint8
Shape: (551, 603, 3)

ImageMetadata is the information about the image, including the pixel type, pixel precision and image layout, which define fundamentally how the pixels arranged in buffer.

print(metadata.fileInfo)

The result could be like this:

{'pixelPrecision': 8, 'imageLayout': 'interleaved', 'pixelType': 'rgb'}

Some file formats need to know in advance some informations about the image. For example, the PLAIN format is just a simple dump of a buffer into a file, thus it needs to know how to interpret the data.

image, metadata = read_image(Path('/path/to/image.plain16'))

In this case, user need to have an image sidecar JSON located next to the image file as the same name and path '/path/to/image.json'

{
    "fileInfo": {
        "format": "plain",
        "height": 3072,
        "width": 4080
        "pixelPrecision": 16,
        "pixelType": "bayer_gbrg",
    }
}

After image reading, the information in JSON sidecar is parsed in ImageMetadata object.

The result of print(metadata.fileInfo)could be like this:

{'width': 4080, 'height': 3072, 'pixelPrecision': 16, 'imageLayout': 'planar', 'pixelType': 'bayer_gbrg'}

Image sidecar is not mandatory, for the other formats which have already image information in their header, like jpg, png, tif, cfa. we don't need to provide image metadata.

Split and merge image channels

After calling read_image, cxx-image-io provides a public API split_image_channels which helps to split to different colors channels, so that user can do the different processes on them. The function return type is a dictionary which contains the different color channel name as keys, and the value in numpy array of one single channel.

before calling write_image, cxx-image-io provides a public API merge_image_channels which helps to merge different colors channels to a numpy array buffer.

from cxx_image_io import read_image, split_image_channels, merge_image_channels, ImageLayout, ImageMetadata, PixelRepresentation, PixelType
import numpy as np
from pathlib import Path

rgb, metadata = read_image(Path('rgb_8bit.jpg'))

channels = split_image_channels(rgb, metadata)

# print(channels['r'])  # Red channel
# print(channels['g'])  # Green channel
# print(channels['b'])  # Blue channel

rgb_post = merge_image_channels(channels, metadata)

np.array_equal(rgb, rgb_post)

cfa, metadata = read_image(Path('bayer_16bit.plain16'))

channels = split_image_channels(cfa, metadata)

# print(channels['gr'])  # Bayer Gr pixels
# print(channels['r'])  # Bayer R pixels
# print(channels['b'])  # Bayer B pixels
# print(channels['gb'])  # Bayer Gb pixels

cfa_post = merge_image_channels(channels, metadata)

np.array_equal(cfa, cfa_post)

yuv, metadata = read_image(Path('raw.nv12'))

channels = split_image_channels(yuv, metadata)

# print(channels['y'])  # Y plane
# print(channels['u'])  # U plane
# print(channels['v'])  # V plane

yuv_post = merge_image_channels(channels, metadata)

np.array_equal(yuv, yuv_post)

Image writing

write_image is able to write a numpy array to image file.

To write the pure numpy array to different image file extensions. User need to define the following fundamental parameters in ImageMetadata which is part of ImageWriter.Options. In order to call the specific C++ image libraries with them.

from cxx_image_io import ImageMetadata, ImageWriter, FileFormat, PixelType, ImageLayout
from cxx_image_io import write_image
import numpy as np
from pathlib import Path

metadata = ImageMetadata()
metadata.fileInfo.pixelType = PixelType.RGB
metadata.fileInfo.imageLayout = ImageLayout.INTERLEAVED

write_options = ImageWriter.Options(metadata)

assert isinstance(image, np.ndarray)
write_image(Path('/path/to/image.jpg'), image, write_options)

write_image can determine the image format by file extensions, but some formats don't not rely on a specific extension, for example the PLAIN format that allows to directly dump the image buffer to a file. In this case, the format can be specified through ImageWriter.Options.

write_options = ImageWriter.Options(metadata)
write_options.fileFormat = FileFormat.PLAIN

assert isinstance(image, np.ndarray)
write_image(Path('/path/to/image.plain16'), image, write_options)

EXIF

Some image formats, like JPEG and TIFF, support EXIF reading and writing.

If supported, EXIF can be read by calling read_exif and be written by calling write_exif.

from cxx_image_io import read_exif, write_exif
from pathlib import Path

exif = read_exif(Path('/path/to/image.jpg'))

print(exif)

write_exif(Path('path/to/new_image.jpg'), exif)

print(exif) will give the following output like:

{'make': 'Canon', 'model': 'Canon EOS 40D', 'orientation': 1, 'software': 'GIMP 2.4.5', 'exposureTime': [1, 160], 'fNumber': [71, 10], 'isoSpeedRatings': 100, 'dateTimeOriginal': '2008:05:30 15:56:01', 'exposureBiasValue': [0, 1], 'focalLength': [135, 1]}

user can use help(exif) to see the definition of Exif metdata.

EXIF metadata can be read and written along with an image by specifying them in the ImageMetadata. In this case, the EXIF wil be read and written when calling read_image and write_image.

image, metadata = read_image(Path('/path/to/image.jpg'))
metadata.exifMetadata.make = 'Custom'
write_options = ImageWriter.Options(metadata)
write_image(Path('/path/to/image.jpg'), image, write_options)

License

This project is licensed under the MIT License - see the LICENSE.md 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

cxx_image_io-1.0.3.tar.gz (22.3 kB view details)

Uploaded Source

Built Distributions

cxx_image_io-1.0.3-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13 Windows x86-64

cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.28+ x86-64

cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.28+ ARM64

cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13 macOS 11.0+ x86-64

cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

cxx_image_io-1.0.3-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12 Windows x86-64

cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.28+ x86-64

cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.28+ ARM64

cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12 macOS 11.0+ x86-64

cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

cxx_image_io-1.0.3-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ ARM64

cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11 macOS 11.0+ x86-64

cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

cxx_image_io-1.0.3-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.28+ ARM64

cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

Details for the file cxx_image_io-1.0.3.tar.gz.

File metadata

  • Download URL: cxx_image_io-1.0.3.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for cxx_image_io-1.0.3.tar.gz
Algorithm Hash digest
SHA256 6b9d63c2d20ac9131603f067d0d4a89a30018dc4a5f8516711c3e61339ebd188
MD5 b74e3751e4d25b609959adb059aefdb3
BLAKE2b-256 fc9c8027911c68b999e039a9258f8c628db8f1f93dec094c8ce03e96166cd473

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b4d2eb2993e5f107372da8c4bda44af55eb51fa326949bdcc8778cea31c7e0b2
MD5 27a9e0a1f7ff22460695e4c097d0e36c
BLAKE2b-256 50cb240ad54a53b96abb98d25a984429bc604ee78c95455c7ee2d25e7070a864

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7d805417b60b39c62b0b67c1e48b6747c1d61a6a2d3c3b6665d3b1337e117fef
MD5 8970c8ff95bfb0aaed788939ed3b20fa
BLAKE2b-256 58f9d62c29c943e3ce320d968f3fa7253b363a0d222bd2fa9fe5337196f40c9c

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 094bf22fd3ee088d50c2694f40bd7b18ab7e8b50ad1794ca2a27676bce7b07a3
MD5 bac02f46278ac93a4b2e5d5e2d47a658
BLAKE2b-256 e0d6de98cf60da36b2ab7dccd59f14503bb916e483a76affd74b1ee9cbcca124

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9f7feed7224a943a6566e5c65c7fc54293519c399b88d469d37c896e6562d165
MD5 1803e172b4637ba0fc17eaaeff8dd944
BLAKE2b-256 86a136dfa53de3767154d9670f98a58475f9d65035d3d30f30540ba182423b86

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 354cc094ce9ff2f167fc39b8b5fa05df67ed2ec31db660cb786a11cd6bdadc31
MD5 36b40e964bc425363756a4903c73f87c
BLAKE2b-256 14ed6129039d150e076e61ee03d6da5459103a1a892987685503bde836bf4505

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2a03ab93a6a02a61fadede2abb24fb054bf0ec799bba098879d869203a8c736c
MD5 719999cc0813febad06fa1043138c85b
BLAKE2b-256 5ddfcaf003ab24f33c7447eb291c98b04ff0dfbadc1060d5a8d664268a1ccecf

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2bda64fb6d380e8022605c351c0c2462f7de50957df1eb1b270eb059dc10ba33
MD5 bd76014cb69e9b6a53867c462009a45e
BLAKE2b-256 550de54f66557619cfb998c9bea6f49a81cfe06d975f5c25eafaf7ff8ade483c

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4e231dad8cd7fd64a3fc00447b234b994c153fd0e943efcbc22202bc484d30ec
MD5 356cdb9e498af4b01519baf868024561
BLAKE2b-256 34a6e31eb3c58641ad4ba7fe9ac52d63b946e2c0c1123e11a0072a68f167e364

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bb6e454b91c4ae5ceae3bf7c41e03a021e2f81c672c20955f5129686c2508bf0
MD5 ffea546e60513b341dbf18cc81e4a96f
BLAKE2b-256 79d08ab480dc7d0b0289e0f6f9d1ff4f9f911e77fe10abf798853dfd46cea869

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e57f7d994f9e23f18d43bd925df258528f59271b425b9cd1d71d559aaf7dded
MD5 3665cb5b285b9b69b31b7222a44b52b5
BLAKE2b-256 a0ac9e700a6ecc451e8e4537c666a99d604c31cbba35bb91b69444090ea26ecd

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc98c8aed8b217c711a6b3327b17bc50777d2de30f6695da9a89177a5df450d4
MD5 625976b569d08395494b350399c4a6a3
BLAKE2b-256 c49c19d2df222ee6d435b448164b3d13df1c9e11c0aa62fea236fe0df2b4e84f

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79a46aa4fab694f6cb3264a4ed1a6f7fb77d89ad3d7b7d9aa5cd8ae52dd32c8f
MD5 c459b689c8a12f45d61568d9605932af
BLAKE2b-256 7ae68e61cb25d23cb2febfa63287c6a13d147352211942294e5d0a58e07a47d9

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c89e1a1ae0fb1a2b1c68b8660a9fdc1f294adb65264e7255f1fb9020c3aa4b17
MD5 a80bdc65f6299dc1aa621471e0129e3d
BLAKE2b-256 0e3c29e3779da06603e9d24109fd5c36eb71beb9dc8ca96c3d924b0460546b26

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 edb4537bb04f2072c7e4bddfd76978aae77b971d68595c9d413a0a677f09fc42
MD5 caf1e3d6f4de42658f8a9b409f09b9dc
BLAKE2b-256 dec416017ee499bc3a432cca9bb14aa1312f84003c1ebb038634b0e1afa97c91

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 948fcf36c33ef44959a642ca8cc5def6353bb806971eb03115063e2393d402bd
MD5 e1ecc1d2f00d57752326b971a8ac19ed
BLAKE2b-256 050eb5f1524a2cd8e728394af7cc35a5555c6ab3c9aead2c1ad36e38c5c0e884

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 430633b8b5b7241d7bca07f9bc1c170dbcee9741c8db2bbee3a38ddfd9a1a79a
MD5 6fda6a2f2aa36ad3bd6ea3fffd0a4970
BLAKE2b-256 bad7b2551634aecf0d76081a0b11018203761b0030efa4caf2257e7a8432ca3d

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b24f4bbf45bdf86e29ee7d56142483b8990609e2a38e64e6700ea2cf9c16dac
MD5 5ce69b7e818148917d52efd7d1fd42a5
BLAKE2b-256 6e244da5c149fd8d89017917a35e05d05d68ca6fcf6cd2c7b9ba9c876ec59fd2

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a28d70747834419d9f90887cd2270a4e02f4283fea9681c858aa1e7e852e397e
MD5 97d8d46f102d1b45d4e365462fbb972c
BLAKE2b-256 cd8518f902db189cc2500c6a0a3053ede7842cff110e70685a7710ec9519f2f8

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0cfe93aeb9b78d2bba70da0bd4895e74c284831cd6357b897f2f812c9e35b244
MD5 b9fc1bc8b2feaafd7018125d3618d9dd
BLAKE2b-256 6d525181ce7c26f43f0861b8ded7fe735db135bf962c7ef348cfc8b26c113256

See more details on using hashes here.

File details

Details for the file cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cxx_image_io-1.0.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1779ed4d0aeef71b6aa18a3762c2eea536b07cd9fe4cf555051b307f676b7e5c
MD5 9c7b5406c8f655ddf29f7de7d820b838
BLAKE2b-256 c5a4db6017fc04168787b0b7cf91547fcd665a0bbec77ac271e2fd31f3f39172

See more details on using hashes here.

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