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:
rayon
: ParallelizesGenericImageRef::to_luma
(and similar),GenericImageRef::to_luma_custom
,GenericImageRef::into_u8
andGenericImageRef::debayer
functions (enabled by default).serde_flate
: Compresses the data using deflate during serialization (enabled by default).fitsio
: ExposesFitsWrite
trait to writeGenericImageRef
andGenericImageOwned
(disabled by default).image
: EnablesTryFrom
conversions betweenDynamicImage
andDynamicImageRef
,DynamicImageOwned
(disabled by default).
Structs§
- Generic
Image Owned - A serializable, generic image with metadata, backed by
DynamicImageOwned
. - Generic
Image Ref - A serializable, generic image with metadata, backed by
DynamicImageRef
. - Generic
Line Item - A metadata item.
- Image
Owned - A structure that holds image data backed by a vector.
- Image
Ref - A structure that holds image data backed by a slice or a vector.
- Optimum
Exposure - Configuration used to find the optimum exposure.
- Optimum
Exposure Builder - Builder for the
OptimumExposure
calculator.
Enums§
- Bayer
Error - Error codes for the Bayer demosaicing.
- Bayer
Pattern - Enum to describe the Bayer pattern of the image.
- Color
Space - Description of the color space of the image.
- Demosaic
Method - The demosaicing algorithm to use to fill in the missing color channels.
- Dynamic
Image image
- A Dynamic Image
- Dynamic
Image Owned - Image data with a dynamic pixel type, backed by owned data.
- Dynamic
Image Ref - Image data with a dynamic pixel type, backed by a mutable slice of data.
- Fits
Compression fitsio
- Compression algorithms used in FITS files.
- Fits
Error fitsio
- Enumeration of all error types
- Generic
Image - A serializable, generic image with metadata, backed by either
a
GenericImageRef
or aGenericImageOwned
. - Generic
Value - A type-erased enum to hold a metadata value.
- Pixel
Type - 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
orGenericImage
.
Traits§
- Bayer
Shift - A trait for shifting Bayer patterns.
- Calc
OptExp - 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. - Fits
Write fitsio
- Trait for writing objects to FITS files.
- Image
Props - A trait for accessing the properties of an image.
- Pixel
Stor - 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.