Crate refimage

Source
Expand description

Crate to handle image data backed either by a contiguous slice or a vector.

The image data is stored in a row-major order and can be of different pixel types - u8, u16, and f32. The image data supports arbitrary color spaces and number of channels, but the number of channels must be consistent with the length of the backing storage. The image size is limited to 65535 x 65535 pixels. In case the image is a Bayer mosaic image, the crate supports debayering of the image data.

The crate additionally supports serialization and deserialization of the image data using the serde framework.

The crate provides a concrete type ImageRef to store image data and a type-erased version DynamicImageRef to store image data with different pixel types. Additionally, the crate provides a GenericImageRef type to store a DynamicImageRef with additional metadata, such as the image creation timestamp, and many more. The metadata keys must be 80 characters or less. Uniqueness of the keys is not enforced, but is strongly recommended; the keys are case-insensitive.

The crate, with the optional image feature, provides can convert between DynamicImageRef and DynamicImage from the image crate. With the optional fitsio feature, the crate can write a GenericImageRef, with all associated metadata, to a FITS file.

§Usage

use refimage::{ImageRef, ColorSpace, DynamicImageRef, GenericImageRef, GenericImageOwned};
use std::time::SystemTime;
use std::path::Path;

let mut data = vec![1u8, 2, 3, 4, 5, 6, 0, 0]; // 3x2 grayscale image, with extra padding that will be ignored
let img = ImageRef::new(&mut data, 3, 2, ColorSpace::Gray).unwrap(); // Create ImageRef
let img = DynamicImageRef::from(img); // Convert to DynamicImageRef
let mut img = GenericImageRef::new(SystemTime::now(), img); // Create GenericImageRef with creation time info
img.insert_key("CAMERANAME", "Canon EOS 5D Mark IV".to_string()).unwrap(); // Insert metadata
let serialized = bincode::serialize(&img).unwrap(); // Serialize the image
let deserialized: GenericImageOwned = bincode::deserialize(&serialized).unwrap(); // Deserialize the image

§Optional Features

Features are available to extend the functionalities of the core refimage data types:

Structs§

Enums§

Constants§

Traits§

  • A trait for shifting Bayer patterns.
  • Trait to calculate the optimum exposure time and binning.
  • A trait for copying a region of interest (ROI) from one image to another.
  • Trait to apply a Demosaic algorithm to an image.
  • A data format that can deserialize any data structure supported by Serde.
  • An Enlargable::Larger value should be enough to calculate the sum (average) of a few hundred or thousand Enlargeable values.
  • FitsWritefitsio
    Trait for writing objects to FITS files.
  • A trait for accessing the properties of an image.
  • The type of each channel in a pixel. For example, this can be u8, u16, f32.
  • A trait for selecting a region of interest (ROI) from an image.
  • A data format that can serialize any data structure supported by Serde.
  • A trait for converting an image to a luminance image.