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>

source

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 type DynamicImageData.
§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();
source

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, a String, or a std::time::Duration or std::time::SystemTime or a tuple of a primitive type and a comment ().
§Valid Types

The valid types for the metadata value are:

§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::Duration or std::time::SystemTime is split and stored as two consecutive metadata items, with the same key, split into seconds (u64) and microseconds (u32).
source

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.
source

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, a String, or a std::time::Duration or std::time::SystemTime or 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.
source

pub fn get_image(&self) -> &DynamicImageData<'a>

Get the underlying DynamicImageData.

§Returns

The underlying DynamicImageData of the GenericImage.

source

pub fn get_metadata(&self) -> &[GenericLineItem]

Get the contained metadata as a slice of GenericLineItems.

§Returns

A slice of GenericLineItems containing the metadata.

source

pub fn get_key(&self, name: &str) -> Option<&GenericLineItem>

Get a specific metadata value by name.

Returns the first metadata value with the given name.

§Arguments
  • name: The name of the metadata value.
source§

impl<'a, 'b> GenericImage<'a>
where 'a: 'b,

source

pub fn operate<F>(&'a self, f: F) -> Result<GenericImage<'b>, &'static str>
where F: FnOnce(&'a DynamicImageData<'a>) -> Result<DynamicImageData<'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
source

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.
source

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>

source§

fn clone(&self) -> GenericImage<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, 'b> Debayer<'a, 'b> for GenericImage<'b>
where 'a: 'b,

source§

fn debayer( &'b self, method: DemosaicMethod, ) -> Result<GenericImage<'b>, BayerError>

Debayer the image using the specified algorithm.
source§

impl<'a> Debug for GenericImage<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a> From<GenericImage<'a>> for GenCamOk<'a>

source§

fn from(image: GenericImage<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> PartialEq for GenericImage<'a>

source§

fn eq(&self, other: &GenericImage<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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,

Serialize this value into the given Serde serializer. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,