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.2.tar.gz (22.3 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.13 Windows x86-64

cxx_image_io-1.0.2-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.2-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.2-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.2-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.2-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12 Windows x86-64

cxx_image_io-1.0.2-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.2-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.2-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.2-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.2-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

cxx_image_io-1.0.2-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.2-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.2-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.2-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.2-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

cxx_image_io-1.0.2-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.2-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.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: cxx-image-io-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 86723c53b2869ea30aef048239aaae71925b57db1bb5c9707bbbe7b976e49ce2
MD5 ab8ef3e64653bdc4c7566c03e6601817
BLAKE2b-256 943efb9578e9e162845aa4c10b4e597dacef50d48b40ef910570979a5a95cdf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7fd654b47afab66792547fea87acad615409a8837d1d8dde2f1aa1925de5607b
MD5 0353d607fad43e05f0eb7085c8df916f
BLAKE2b-256 8dcecc7df1cebb140d6d5ffa7fbc4ad7cae7aa1446f9d86ffc7e7e19dd7db04e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1246074e187277ce1b90180664fa12fafc578654d8c6ff92bcfa773597664b62
MD5 0a2d9d52061dc7fcda0855662b75e4ec
BLAKE2b-256 a93434f7677944d6cc23a7e37f1a12583a792d02f8cc2379379762ea6724962c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0e067e04ddaf0b162ed382427d11d9363615224bd9c6256aa0d24894ac71b01e
MD5 7ccd9d3359a1666969084df351ac9d33
BLAKE2b-256 bf49ae699f08c7e6d7339ce21ccfe347f0ee4e7fec1cf3ac2e12ee45ac6a2396

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3f1f79c31846c2e8737f34c43aef85870ef86f7ce9317ce468fe07f0138f6d5b
MD5 b980bdcb98f4696e2cd704cf1b67f8ec
BLAKE2b-256 56d57a3abc8b742dbe0918a8ee98ee2070b35ced809047c56a79bc4df1f6407d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f40732343e9159c776c9fbeafa8c4b5ecb45f2d30cf687000eeb3ff2a539bf1
MD5 f4720f479ed08e4537925bcd72d1d567
BLAKE2b-256 cd1bbae7082a66c7a2cd913d8377a18b3109058fc93853662d4cc0051a9bf7d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 650a07c5f10f34ee62024e7dd723f4768651b6ddd9e786792686456a3153860c
MD5 822145785b8aa25ab93cb97b5cb77cf6
BLAKE2b-256 ae067dc0e124c317173e732ebbbbee887dc0c05db4611d1fcffc3c596fc3a927

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9cb8da29283f158aed70d0cea62882c61f5aac3d0fddfa1d4457b61bc180d65e
MD5 78bba38b8baed9a3cca2acfc9831ab64
BLAKE2b-256 c04600f9482443cc7bd162ecb9c555c1b5c3f14f209367c3e9b4a33f2c92497e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bf0aac6b98fa4628bdfbde4ac7c27e062d60d0f3037318dc01467e55ff9f9a15
MD5 cf275bf7961140e2fa95b3a91e83c49f
BLAKE2b-256 cbd55ffb62aa6afccd56b4785e07afdcd71f03b1451ddda605d5f2cd34d2dc68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 89c0ad81ebe5f0f4624899222e21f6a930f45ffb9d1005a17ba7c49f55b76181
MD5 507cf3ff8d3d0af5c7a9f092574ea978
BLAKE2b-256 1a60b2d5ef8b65b355792f68cb048b19086d1438bc25ed230ceb0c02f2a47259

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f5df881980f159bec2fafd169917a3108b235ff13cabccf3562cee63fb36af4
MD5 d86f583f77712f0edc6c34658ca197dc
BLAKE2b-256 3da1804a1936706f87d21071072c0a95c0086388e63682596cca8d8fa6ffedd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 63c6ad0638ddc35d9b1cd61b68d4b60c3288526af02eeec47cf2d755e2def668
MD5 49a1d2acefa061d1247a07483623496d
BLAKE2b-256 ee6f25b9170a6de5180b18df1e7c1d7dd308d91340b4c6bf1b76ccd6136c5b3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9121e4fbf99f0a350463aada4f1a9564c3ada94d49fb2c3c885f8d874f6534c8
MD5 4e6c05eea42ff462cd510bb63b51bf7f
BLAKE2b-256 3ab14c9830f9f6b778fe9d496148daa13975341ecfde69c44ca79ea853214cb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bed9f5bde9d2ecddeeb6e476b3b0e95b4a5534d877b86e4aa07586571e79f5f2
MD5 769f3f869f799e4f7d8127f478fcb167
BLAKE2b-256 a08e2fb05523c58bafe3e3eec3f6970908048104829defada089a85245104907

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ce5986715f5db5837f35598a56b68bc8ac37559a8f11d99a78834dd60c0c8048
MD5 a712a1dbaf854224b00270a2b882c923
BLAKE2b-256 78f0c84173a3d307784d71be47467b0e59dd7033462b65298bcf50d4762727f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e280c3606e32a56ef7e0e85f539f6602c9a4f3a259e23edfecb36278831d6b74
MD5 500b66fb0e1b04c0970a65c1633e5836
BLAKE2b-256 deda292255ad9947d5e77446c98324dfc178624fff9b1750e1e6d79275fe5575

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d002384e5e9aa6d116fc250e16d0caed66700568b18c96876eb33bd12de7fa1b
MD5 c1ce14af8b9f6ed2fdb3d82393226d6e
BLAKE2b-256 fc1e1d48135881775194d7ff04106f93ac0159101c87608cdab7687b4efa32e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c31f3a4ac726df608f5bec562f62c95c193f1d5acf69731c5abf88efe3b1b1c4
MD5 3132ce3e11cf5e2211c35671b6de0863
BLAKE2b-256 d1f39a02717778d7be282116e2100db3f396903ce516feda0cd5061bdd65b866

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eae515ef4600cfae8d4be6560cbaba41cb6c4d7c8d4eb9fd08ed8dde284ca59c
MD5 98d56b403bc28a5100e778d91405a021
BLAKE2b-256 8361c6c602b73f3503247595174e37f568bc8d0b4469734d8dd07bec7d5a471f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0733f180e7b7b8ca424ab99a4a901c90c625666d0331e8d064d577fc0c4f3b72
MD5 c9d5e38d1ef7dcc449b6a74e7fd580f1
BLAKE2b-256 13c65b3231fba92825ba7e9f8f350f3b018eef3d330741f468fceeb416c24513

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65bc0928b433da293ca6882fcfb9d4be4c8139c58f42e6e869bf4593bc688654
MD5 ef623669ba387c1a4c98c7ab48766fdd
BLAKE2b-256 17fedf098acec58c5f45c141f2025638ff9cc3e5335b8b0583566b21f2869b14

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