refimage
A Serializable Image Container
This crate provides a type-erased image container (GenericImage), backed by a contiguous
slice (owned or referenced) of primitive (u8, u16, f32) pixels, with arbitrary
color space (grayscale, Bayer pattern, RGB, ...) and color channels support (max. 255).
Image sizes are limited to 65536 × 65536 for practical reasons.
GenericImage is powerful, since it supports metadata in the form of (key, value) pairs,
with optional comments. Valid metadata keys are case-insensitive, 80-character strings, and
values are up to 64-bit integer types, 32- and 64-bitfloating point numbers, strings up-to
4096 characters, or std::time::{SystemTime, Duration}.
GenericImage also supports serialization and deserialization, and, optionally can be saved
in the open Flexible Image Transport System (FITS)
format by enabling the optional fitsio feature. FITS files support lossless compression,
and saving of arbitrary metadata.
The path to a GenericImage
A GenericImage can be obtained in a couple of ways. In the first case, the Rust program
itself generates the image. In that case, a ImageData object is first created with the
appropriate, contiguous, backing storage and image format:
use ;
use SystemTime;
let mut data = vec!; // this is the backing store
// acquire(&mut data); // this function populates the backing store with the image pixels
let img = from_mut_ref.unwrap; // Create a 4x4 image backed by the vector
let img = from; // convert the `ImageData` object to `DynamicImageData`
let img = img.debayer.expect; // debayer the image using nearest neighbor method
let mut img = new; // Convert to a GenericImage
// insert the camera information as metadata
img.insert_key;
let json = to_string.unwrap; // serialize the image to JSON
let rimg: GenericImage = from_str.unwrap; // deserialize to GenericImage
assert_eq!; // Confirm that deserialized image matches the original
In the second case, an image can be loaded with the image from disk, by enabling the image feature:
use DynamicImageData;
use open;
let img = open.expect;
let img = try_from.expect;
Note, that the image being loaded must not contain an alpha channel for the conversion to be
successful in the current implementation. However, the image crate provides methods to
remove the alpha channel. A custom color space can be used for such an image, however,
the user must keep track of the custom color space information.
Loading and storing a GenericImage
A GenericImage is intended to be loaded and stored in a standard format, e.g. bincode - which follows trivially from the serialization-
deserialization of GenericImage. However, for more portable applications, with the fitsio
feature, a GenericImage can be stored as a FITS file. The FITS file is stored using the
fitsio crate, which is a thin wrapper around the
cfitsio library.