Skip to main content

Python image IO module with binding cxx image code

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 is necessary

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.13 Windows x86-64

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

cxx_image_io-1.0.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: cxx-image-io-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d839b43e897299b00e1d6e08b6c8adcbbbdc5f372ed9aa21d5a12249282d7aeb
MD5 02b727ce44ea719963e612ac76175fc6
BLAKE2b-256 42524791e6a4429d21d091109bb8054bd515c5d2f14680037572f7657b75b146

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f9811c0ac055c8e7d30c019f7ddf9423ecb2e6e55e335fc0fc33b555d5cf5eae
MD5 5d8702a65787afa429ef45b3f8c3d1a9
BLAKE2b-256 310873137190fad3e7a19f9c5d8881ada9b7c85c0e85066f9b93cb01aa0cb335

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 79ebfe3e68ee7cbc949d6b507ae0310a02c23c8d2b561fef40e83bd5dc4f0057
MD5 b880629c8095e8f8b6e7149ad55cbc0e
BLAKE2b-256 d2ec0050c1978f41989842639bb330be0973bb50f427a9d37a9ae3e9a2fb0c7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6dcb9aca5ce5ee904c639f02970d613f61e77612baab1554977aae79eaf50e69
MD5 d6098e9d861de22eadf1f13b4324eb0d
BLAKE2b-256 e17bb8307dffd5a61fc7cefbc3f5cda36303253d96e0eb93e392bae76102d634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 20cb11d7f6c78dce4975e6bb2904fc15e38eb3add67e9e230ff75918fb5f4ed3
MD5 c65a1953af5bfd64f1450520b76ca356
BLAKE2b-256 118f0904b7a47bfae11bb32843fd1dbd47d4d47f65cc726c3ced56dba864e85e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d12c70cdd6b032f8027b4812e81ae632051d7066ddb0ea52b151cf3e6b71c3c
MD5 de55125bb5bc133b3660c4b3f799ad22
BLAKE2b-256 62d3e30dd9861d402db0090999299e61a010628e05cf1bcf74c49f87437026ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4d123dcdbbeb17bde52c806974f83daf629b378e557947c06b2f0295a10a2155
MD5 ad6324c10b5bcd0d8de119c9a7780095
BLAKE2b-256 285136e22ba9b2d5176cd670da4eca335b7198afeb6e7fb30df201e806bf4158

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b59d3a1ebd91f074036165f7fc090f232d9436f3183ec9b7c5d3693487012e7b
MD5 56e2916e2ebc1dfdd6686ace147fa47f
BLAKE2b-256 779f5a8c09ad6ff92cd801d47e6f1a442394611b1c2ec7e3c57cde1fc7ff11bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 452569c01b421d4a9795b2d7fd72968da850f2eb86907b3d8bbf4d1b0fd90b78
MD5 bef47ee1b14c78694b36b844b7dee4a5
BLAKE2b-256 a60e1223f5e5434c784e376cfa1975918f133cdc813ed8d802c02e26a2115202

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b2920d1bc346f005b9dccf3fbc8f708f23700c98597fa88eee5d6afbf96bdf7e
MD5 c50a8aaf074bc692fecb5bb5bec530a0
BLAKE2b-256 74d20cf1d03fc5bb29c035f2b44598e2c72b2f6824f5794967aa5a279ad82b6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f1a6efb3cd3326f8ff8db546f2a4d4c8f14879992f8ed40e9209765c2a1dfaa
MD5 200b9caa3bdd1756a64e4691ad002e17
BLAKE2b-256 fb529a334fa9ceb6d080743ddc68e8e1eca141bb6f7aff01e9596e6765fa1864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3a564407e7913481bead33127309fa624c852a75c914d235f25696502686f573
MD5 292a5f21eac6f5b2e6763c3643e767f1
BLAKE2b-256 3ecdfd7214f7aeae229c0e5576e04e79399f6e226a9258d73c5fab5dfa1a92e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61d88b4a56d5d6e4f1597cb11052f705e2bf9b6fba7b56ac4ceec77e8f3f8c4e
MD5 1796574dc44720c3becf2fec604d7cbd
BLAKE2b-256 7451d0289553df0680f517bf6a346ae347a9013848417c139d9f698d3bf602f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eecde82f465cd9a8a34659b98ab5d2fd855839b18428f649b1f265d320d81347
MD5 a86cc9812bdb5613dd98dc7f259e78fa
BLAKE2b-256 3a4357baf4cd08cedc49b9a47bfac9fa61c64d8479768e4174c7fcf662a3a6a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ac228482f729503c69dd87dbe433662dbecaf658d57d0fa5a76672de4415d737
MD5 e14d26abd2dd057c5debd3c1f50d55a3
BLAKE2b-256 4be6097ba6761a01de1c03fbae5bbcbbc6425c1946927998b9e52f7293deb87b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3f2c54cd335cc307bc65d78c83d3e1c45480bd408db1de24f6594edb907dc49
MD5 5ec814d625b1b95ec339a2627ac12db3
BLAKE2b-256 eda5516ffd0711e16786215e5e29a5d46bceb5a19390c2654b16781a5a56231f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2db14cbd8824839145d185686d680e74f23669bd790112b79b7fb2450fbbb28b
MD5 8f7c75f047fc4cd5f301f840d843942f
BLAKE2b-256 4c2f40064ea4b10801c96808c68ce672ff81ccb473e2fc151dde47df52da5298

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 398252d9dc0a2fb0933b1adf3b6092ccde0d2cd1902173c68c5b87399b25670b
MD5 565fe15b6ce782353748f7f774dc68f1
BLAKE2b-256 84fcbea6e7820799b30b7ace8a36eea355786d291fc37489d8e613b119ac12c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 579f2994b44bd80935f742856c7182e3132b2dcaa09c1801890a68001cee1ffe
MD5 994eb4c0a3db681829d30c23d4bff623
BLAKE2b-256 fa4320afeb7dff8e9e3dc4f60a5b1c2e944639c213b22f71ccfe982c8166cc28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7b546bc96beadcec16084683ac76186dba8de6f6c87bb01df968b67ffdf53570
MD5 17a4115eb4cd624ba4698b4620448c26
BLAKE2b-256 0a15a1f368fdfce3bc2deb6879811bfa1634b39bcce4dc47640610e305ff4a92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9d0c55273f302bf2b4f4ab17c142ce1bca8631cfad3a1b72c789bcf13e439abf
MD5 84601c54c8557063a9ef3db4bae6b58c
BLAKE2b-256 cf3585ae605f29c596be929e44b7c36c42ae1f578e3c1e9f3e33d1bc73f5880e

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