Struct generic_camera::GenericImage
source · pub struct GenericImage<'a> { /* private fields */ }Expand description
A serializable, generic image with metadata.
This struct holds an image with associated metadata. The metadata is stored as a vector of
GenericLineItem structs. The image data is stored as a DynamicImageData.
§Usage
use refimage::{ImageData, DynamicImageData, GenericImage, ColorSpace};
use std::time::SystemTime;
let data = vec![1u8, 2, 3, 4, 5, 6];
let img = ImageData::from_owned(data, 3, 2, ColorSpace::Gray).unwrap();
let img = DynamicImageData::from(img);
let mut img = GenericImage::new(std::time::SystemTime::now(), img);
img.insert_key("CAMERA", "Canon EOS 5D Mark IV").unwrap();Implementations§
source§impl<'a> GenericImage<'a>
impl<'a> GenericImage<'a>
sourcepub fn new(tstamp: SystemTime, image: DynamicImageData<'a>) -> GenericImage<'a>
pub fn new(tstamp: SystemTime, image: DynamicImageData<'a>) -> GenericImage<'a>
Create a new GenericImage with metadata.
§Arguments
tstamp: The timestamp of the image.image: The image data, of typeDynamicImageData.
§Example
use refimage::{ImageData, DynamicImageData, GenericImage, ColorSpace};
use std::time::SystemTime;
let data = vec![1u8, 2, 3, 4, 5, 6];
let img = ImageData::from_owned(data, 3, 2, ColorSpace::Gray).unwrap();
let img = DynamicImageData::from(img);
let mut img = GenericImage::new(std::time::SystemTime::now(), img);
img.insert_key("CAMERA", "Canon EOS 5D Mark IV").unwrap();sourcepub fn insert_key<T>(
&mut self,
name: &str,
value: T,
) -> Result<(), &'static str>where
T: InsertValue,
pub fn insert_key<T>(
&mut self,
name: &str,
value: T,
) -> Result<(), &'static str>where
T: InsertValue,
Insert a metadata value into the GenericImage.
§Arguments
name: The name of the metadata value. The name must be non-empty and less than 80 characters.value: The value to insert. The value is either a primitive type, aString, or astd::time::Durationorstd::time::SystemTimeor a tuple of a primitive type and a comment ().
§Valid Types
The valid types for the metadata value are:
u8|u16|u32|u64i8|i16|i32|i64f32|f64std::time::Duration|std::time::SystemTimeString|&str
§Note
- The metadata key is case-insensitive and is stored as an uppercase string.
- Re-inserting a timestamp key will return an error.
- When saving to a FITS file, the metadata comment may be truncated.
- Metadata of type
std::time::Durationorstd::time::SystemTimeis split and stored as two consecutive metadata items, with the same key, split into seconds (u64) and microseconds (u32).
sourcepub fn remove_key(&mut self, name: &str) -> Result<(), &'static str>
pub fn remove_key(&mut self, name: &str) -> Result<(), &'static str>
Remove a metadata value from the GenericImage.
§Arguments
name: The name of the metadata value to remove.
§Returns
Ok(())if the key was removed successfully.Err("Can not remove timestamp key")if the key is the timestamp key.Err("Key not found")if the key was not found.Err("Key cannot be empty")if the key is an empty string.Err("Key cannot be longer than 80 characters")if the key is longer than 80 characters.
sourcepub fn replace_key<T>(
&mut self,
name: &str,
value: T,
) -> Result<(), &'static str>where
T: InsertValue,
pub fn replace_key<T>(
&mut self,
name: &str,
value: T,
) -> Result<(), &'static str>where
T: InsertValue,
Replace a metadata value in the GenericImage.
§Arguments
name: The name of the metadata value to replace.value: The new value to insert. The value is either a primitive type, aString, or astd::time::Durationorstd::time::SystemTimeor a tuple of a value type and a comment.
§Returns
Ok(())if the key was replaced successfully.Err("Key not found")if the key was not found.
sourcepub fn get_image(&self) -> &DynamicImageData<'a>
pub fn get_image(&self) -> &DynamicImageData<'a>
sourcepub fn get_metadata(&self) -> &[GenericLineItem]
pub fn get_metadata(&self) -> &[GenericLineItem]
Get the contained metadata as a slice of GenericLineItems.
§Returns
A slice of GenericLineItems containing the metadata.
source§impl<'a, 'b> GenericImage<'a>where
'a: 'b,
impl<'a, 'b> GenericImage<'a>where
'a: 'b,
sourcepub fn operate<F>(&'a self, f: F) -> Result<GenericImage<'b>, &'static str>
pub fn operate<F>(&'a self, f: F) -> Result<GenericImage<'b>, &'static str>
Apply a function to the image data.
This function copies the metadata of the current image, and replaces the underlying image data with the result of the function.
§Arguments
f: The function to apply to the image data. The function must take a reference to anDynamicImageDataand return aDynamicImageData.
sourcepub fn into_luma(&'a self) -> Result<GenericImage<'b>, &'static str>
pub fn into_luma(&'a self) -> Result<GenericImage<'b>, &'static str>
Convert the image to a luminance image.
This function uses the formula Y = 0.299R + 0.587G + 0.114B to calculate the
corresponding luminance image.
§Errors
- If the image is not debayered and is not a grayscale image.
- If the image is not an RGB image.
sourcepub fn into_luma_custom(
&'a self,
coeffs: &[f64],
) -> Result<GenericImage<'b>, &'static str>
pub fn into_luma_custom( &'a self, coeffs: &[f64], ) -> Result<GenericImage<'b>, &'static str>
Convert the image to a luminance image with custom coefficients.
§Arguments
wts: The weights to use for the conversion. The number of weights must match the number of channels in the image.
§Errors
- If the number of weights does not match the number of channels in the image.
- If the image is not debayered and is not a grayscale image.
- If the image is not an RGB image.
Trait Implementations§
source§impl<'a> Clone for GenericImage<'a>
impl<'a> Clone for GenericImage<'a>
source§fn clone(&self) -> GenericImage<'a>
fn clone(&self) -> GenericImage<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a, 'b> Debayer<'a, 'b> for GenericImage<'b>where
'a: 'b,
impl<'a, 'b> Debayer<'a, 'b> for GenericImage<'b>where
'a: 'b,
source§fn debayer(
&'b self,
method: DemosaicMethod,
) -> Result<GenericImage<'b>, BayerError>
fn debayer( &'b self, method: DemosaicMethod, ) -> Result<GenericImage<'b>, BayerError>
source§impl<'a> Debug for GenericImage<'a>
impl<'a> Debug for GenericImage<'a>
source§impl<'de, 'a> Deserialize<'de> for GenericImage<'a>where
'de: 'a,
impl<'de, 'a> Deserialize<'de> for GenericImage<'a>where
'de: 'a,
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<GenericImage<'a>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<GenericImage<'a>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl<'a> From<GenericImage<'a>> for GenCamOk<'a>
impl<'a> From<GenericImage<'a>> for GenCamOk<'a>
source§fn from(image: GenericImage<'a>) -> Self
fn from(image: GenericImage<'a>) -> Self
source§impl<'a> PartialEq for GenericImage<'a>
impl<'a> PartialEq for GenericImage<'a>
source§impl<'a> Serialize for GenericImage<'a>
impl<'a> Serialize for GenericImage<'a>
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<'a> StructuralPartialEq for GenericImage<'a>
Auto Trait Implementations§
impl<'a> Freeze for GenericImage<'a>
impl<'a> RefUnwindSafe for GenericImage<'a>
impl<'a> Send for GenericImage<'a>
impl<'a> Sync for GenericImage<'a>
impl<'a> Unpin for GenericImage<'a>
impl<'a> !UnwindSafe for GenericImage<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)