| Crates.io | serialimage |
| lib.rs | serialimage |
| version | 4.1.1 |
| created_at | 2023-10-03 22:57:21.458393+00 |
| updated_at | 2024-04-14 17:54:05.508632+00 |
| description | Serialization for the [image](https://crates.io/crates/image) crate's DynamicImage type, with additional metadata. |
| homepage | https://crates.io/crates/serialimage |
| repository | https://github.com/sunipkm/serialimage |
| max_upload_size | |
| id | 991628 |
| size | 111,515 |
This crate extends the image crate with serializable DynamicImages: the DynamicSerialImages.
Additionally, it implements an ImageMetaData struct to pack additional metadata information.
Note, however, the metadata information is lost on conversion from DynamicSerialImage to DynamicImage.
The DynamicSerialImage struct stores the image data internally in separate channels without additional overhead.
Similar to the image crate, the internal image buffer (SerialImageBuffer for serialimage) supports
base data types of u8, u16 and f32. SerialImageBuffer<u8> and SerialImageBuffer<u16> structs
support both grayscale and RGB images. The SerialImageBuffer<f32> struct only supports RGB images.
Alpha channels are supported for all three types.
Conversions between image and serialimage data types incur memory copy overheads only when
the channel count is > 1, i.e. the images are RGB or contain transparency data due to the differences
in memory layout.
Add the following to your Cargo.toml:
[dependencies]
serialimage = "4.1"
and the following to your source code:
use serialimage::{DynamicSerialImage, ImageMetaData};
Then, you can create a new image metadata object:
let meta = ImageMetaData::new(...);
Then, a DynamicSerialImage can be created from a DynamicImage. For example, with a DynamicImage
from a Luma<u16> pixel type image buffer,
let img = DynamicImage::from(ImageBuffer::<Luma<u16>, Vec<u16>>::new(10, 10)); // create DynamicImage
let mut img = DynamicSerialImage::from(img); // create DynamicSerialImage
img.set_metadata(meta); // set the metadata
let imgstr = serde_json::to_string(&img).unwrap(); // serialize
let simg: DynamicSerialImage = serde_json::from_str(&imgstr).unwrap(); // deserialize
assert_eq!(img, simg);
Now img can be sent on its merry way with full serialization
DynamicSerialImage and SerialImageBuffer implements the TryFrom and TryInto traits
for image::DynamicImage and image::ImageBuffer.
Additionally, the Serial image types optionally support saving as FITS images (method savefits()).
This feature is not enabled by default, and is available behind the fitsio feature flag. This
feature flag can be enabled to allow for FITS image storage.
Add the following to your Cargo.toml to enable this:
[dependencies]
serialimage = { version = "4.1", features = ["fitsio"] }
The FITS I/O is hidden behind a feature flag to avoid compilation errors on wasm targets.