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, by default, compiles with the [flate2] crate to compress the data before serialization. The compression can be disabled by setting the serde_flate feature to false.

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§

GenericImageOwned
A serializable, generic image with metadata, backed by DynamicImageOwned.
GenericImageRef
A serializable, generic image with metadata, backed by DynamicImageRef.
GenericLineItem
A metadata item.
ImageOwned
A structure that holds image data backed by a vector.
ImageRef
A structure that holds image data backed by a slice or a vector.
OptimumExposure
Configuration used to find the optimum exposure.
OptimumExposureBuilder
Builder for the OptimumExposure calculator.

Enums§

BayerError
Error codes for the Bayer demosaicing.
BayerPattern
Enum to describe the Bayer pattern of the image.
ColorSpace
Description of the color space of the image.
DemosaicMethod
The demosaicing algorithm to use to fill in the missing color channels.
DynamicImageimage
A Dynamic Image
DynamicImageOwned
Image data with a dynamic pixel type, backed by owned data.
DynamicImageRef
Image data with a dynamic pixel type, backed by a mutable slice of data.
FitsCompressionfitsio
Compression algorithms used in FITS files.
FitsErrorfitsio
Enumeration of all error types
GenericImage
A serializable, generic image with metadata, backed by either a GenericImageRef or a GenericImageOwned.
GenericValue
A type-erased enum to hold a metadata value.
PixelType
Enum to describe the primitive pixel type of the image. The underlying i8 representation conforms to the FITS standard.

Constants§

CAMERANAME_KEY
Key for the camera name metadata.
EXPOSURE_KEY
Key for exposure time metadata of the image.
PROGRAMNAME_KEY
Key for the name of the program that generated this object.
TIMESTAMP_KEY
Key for the timestamp metadata. This key is inserted by default when creating a new GenericImageRef, GenericImageOwned or GenericImage.

Traits§

BayerShift
A trait for shifting Bayer patterns.
CalcOptExp
Trait to calculate the optimum exposure time and binning.
Debayer
Trait to apply a Demosaic algorithm to an image.
Deserializer
A data format that can deserialize any data structure supported by Serde.
Enlargeable
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.
ImageProps
A trait for accessing the properties of an image.
PixelStor
The type of each channel in a pixel. For example, this can be u8, u16, f32.
Serializer
A data format that can serialize any data structure supported by Serde.
ToLuma
A trait for converting an image to a luminance image.
OSZAR »