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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.13 Windows x86-64

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

Uploaded CPython 3.12 Windows x86-64

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

Uploaded CPython 3.11 Windows x86-64

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

Uploaded CPython 3.10 Windows x86-64

cxx_image_io-1.0.1-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.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: cxx-image-io-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 587ae07f69ea1d97fb3448c9bcc8d4c548af9f565ed21bd9cfeaf5ccb4ac11dc
MD5 9cbcbf5a977e009cb8b8fef861aea02e
BLAKE2b-256 8b827c25272f40e0491658d403f298c1de10ac4880c968617dec6e0c2a8c00ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f67cb13413cc09f4a3114c1a2ad6f3ad6fd7af759b1cc0e60b94163bf53bb4de
MD5 b4416aea9fa8502787fadcfe1322c447
BLAKE2b-256 4b416f462539725550c0bf1b54a31bcf47dccad5dfbd7f0c74ebd97f4033d1b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7644a46312a884d38ea3a5bc243b0dd43bcf9c01e80ed3bb566d7a49ab7c7e81
MD5 db7f836ec33262eb0df0a96fd987f468
BLAKE2b-256 fd040025553a13232fa3f839c22168f7336bd57ab9cb5fa2617f40ab1dd377d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a8153b3820c8503d9143333c4f7fcfcb449a6ab46c458fb2fb1adddcf6cf2d9c
MD5 ce7ff89e7a6e48fba8b4ebb2490cc08c
BLAKE2b-256 da1e9e6c10b8a01450a5750e69ba9de0678ddc3fead3df6ae97e9d501512c4f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp313-cp313-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 ac4862776ef8ca619091e1a85f6a5467bbd43d306f1facdf423b5f3ccce0b213
MD5 6a9482bd81d7050bbe08dbd078838899
BLAKE2b-256 229f18b9556c5be34df673bec8d547cba6bf088492818a11b9e88d2b3914652e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b673c10b4ae34359ac077701d6d0ea302d9c8b3053c22162784395ab9324589
MD5 5bf33037063db288dac7e0ec4a82afcf
BLAKE2b-256 f55407f7c1cee91683cca9e1b85f0fa835f25d2923ca5d513588f223a2539088

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 027a7833c090d7bec857e0d69a2df594ea1444b1f67022abfaaf6bab938a6036
MD5 bcdba861419fd988eaf48e564ffa5398
BLAKE2b-256 57109ca67dfda00342956b1270178d7219880ca4a754d98d8b262d6770c04a5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 04b2c97c8bcbbb0a9bcded7bc0f8ebd9cef639aedcaec1aa6b034f52b2e3867b
MD5 0c75b2b0c7f81ee26dbdb9d0b7ebb10c
BLAKE2b-256 b47cc8d7168da7544e0296c0aeb7bc23ee13fbdf21080ca856f02bd606dfee4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 15807657bc5d26ac9b4b5db4fad4174cbd830e980f36f52b54ade6ebab48ae67
MD5 2d3f34897c8df630eb4a519430ef13b4
BLAKE2b-256 60bdd8fdaf279cf0e3126aa7f8e4636ac2d081a117d7ee15673bb07d072e742e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp312-cp312-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 eb45884d87edaf6410af3f5c14b3decd5a7bc064d056f0d4bce903332c4688a7
MD5 fd5381d2a884df5e967ffbdf0a27efde
BLAKE2b-256 7d3ffb69c04a738d3e962ae03f4795fcd26e33d95d5dcd2f579738c9a4cbcbf9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6125abe142ff1d9cb827f652a076aa6ff969d24093caa9984c7211c0568adbbd
MD5 87731bbf5cfd2f39109118f44474182b
BLAKE2b-256 c741bff43b1c28a5313fec46b247e1230289d18879a483b02ddd33cb664757f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7d702335e498720e510cbe2dd13c4d0b9b6d295bbb4cf4c084b7d98cdcb6ae46
MD5 38bf235c8ae75ef42fc976fa5a3121f1
BLAKE2b-256 8b93c85ae74f7d70ac592762acdd4d221a63a55e952b2fe026ee5246c7b43838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a15ef235cc4c39bd4395580c17f56383c600051de9b154279f02a223eae429e7
MD5 1cb120ef365384752a553990cb8778f4
BLAKE2b-256 6806e169e5523608842f5823358ade17fbc6fb8f90fb3c69fc125fa7ddd1b9d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 10b11ef87da5d8bcd3c8b3380af675e72d28c36ac45c68ba9af8145f6e6fe787
MD5 ed68e64d653900f7bd73a4f587127b21
BLAKE2b-256 753a4e2a54b4d623301bc11d1b238e33f87cf53a0e9baacc68fdd6b808effc1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e4273c70a8312af7832b0344af97c54f145738ae02b5c46211533072afedff06
MD5 39c2ed84a2b64e1981dbaf0a93a4d827
BLAKE2b-256 ba421d2b7bb3f6d6157cf7b92e1992105f1ea13a7752bb33013238e033d28449

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66d3ebab5862433b6448dc7c7e874b887d4396bbeb406423dd68d53171733261
MD5 2bf947fd13656a5a81b4758a3ac78b14
BLAKE2b-256 85e3bf4073106804ac30fb1cbad51f79580f4b91e0c26df63f68f572fd08b7b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ca637e6db99e89a3c09ecfbc169106363e7845a1cd819673c8cfa38c596e65c8
MD5 e79f6289e07b382701d3981a21207185
BLAKE2b-256 84c2e3f9feb83e7cf9a3c3e3e3e2149bfe13564a21cadaea344b196fefd6dc49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54bd7847d343c6e8e646964e98e23add371dc648cac0a74c7d26290e161a3b98
MD5 b845b1e7437feaee63df94a0c46423b9
BLAKE2b-256 8bd7485e04a6e419259d22e9303560e059ffe9589172b2602208482c815ae4e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4e1ea12b64de531b98e9be684849de5191153e89a25d79f558145785b9d3d008
MD5 77773c89c99b8d44e7dc87bf160f6b3e
BLAKE2b-256 f3b5a84d8d4fce950e95726b4b40d6e9b90f0258a4c80aec7931488c955c5b7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2e6fd1a9e46bed37f3e7106b653c69ee09d179cc6c5088efce46944c0100479f
MD5 af3869d2600b0da41e5506154902a43b
BLAKE2b-256 194bf3385f990230f80fb161618a3de63c30f7bcb86b6a1588fc86a99049dc18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cxx_image_io-1.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d35d53ac5e5174ce6e5add95488b91a2fc4754950a707cabe9c8d427ff703680
MD5 3b8c74d5e38ac11b9fcd1968ebbfceb0
BLAKE2b-256 0449d5b4bc4cedcf110bc960c065200f3a6feca73cbe35048611d43e26ca7045

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