pub struct Image<T = ()>(/* private fields */);Expand description
Native Wolfram ImageWL or
Image3DWL.
Use UninitImage::new_2d() to construct a new 2-dimensional image.
Implementations§
Source§impl<T: ImageData> Image<T>
impl<T: ImageData> Image<T>
Sourcepub fn as_slice(&self) -> &[T::STORAGE]
pub fn as_slice(&self) -> &[T::STORAGE]
Access the data in this Image as a flat buffer.
The returned slice will have a length equal to
flattened_length().
Examples found in repository?
7fn test_image_arg(image: &Image<bool>) -> NumericArray<i8> {
8 let mut array = UninitNumericArray::from_dimensions(&[image.flattened_length()]);
9
10 for pair in image
11 .as_slice()
12 .iter()
13 .zip(array.as_slice_mut().into_iter())
14 {
15 let (pixel, elem): (&i8, &mut std::mem::MaybeUninit<i8>) = pair;
16 elem.write(*pixel);
17 }
18
19 // Safety: We iterated over every element in `array` and initialized it with the
20 // corresponding pixel value from `image`.
21 unsafe { array.assume_init() }
22}Sourcepub fn get(&self, pixel: Pixel, channel: usize) -> Option<T>
pub fn get(&self, pixel: Pixel, channel: usize) -> Option<T>
Get the value of the specified pixel and channel.
§Example
Get the value of the second channel of the top-left pixel in an image.
// let image: Image<u8> = ...
let value: u8 = image.get(Pixel::D2([0, 0]), 2).unwrap();In an RGB image, this is the value of the green channel for
this pixel.
In an HSB image, this is the value of the saturation for this
pixel.
Source§impl<T> Image<T>
impl<T> Image<T>
Sourcepub fn flattened_length(&self) -> usize
pub fn flattened_length(&self) -> usize
The number of elements in the underlying flat data buffer.
LibraryLink C API Documentation: MImage_getFlattenedLength
Examples found in repository?
7fn test_image_arg(image: &Image<bool>) -> NumericArray<i8> {
8 let mut array = UninitNumericArray::from_dimensions(&[image.flattened_length()]);
9
10 for pair in image
11 .as_slice()
12 .iter()
13 .zip(array.as_slice_mut().into_iter())
14 {
15 let (pixel, elem): (&i8, &mut std::mem::MaybeUninit<i8>) = pair;
16 elem.write(*pixel);
17 }
18
19 // Safety: We iterated over every element in `array` and initialized it with the
20 // corresponding pixel value from `image`.
21 unsafe { array.assume_init() }
22}Sourcepub fn channels(&self) -> usize
pub fn channels(&self) -> usize
LibraryLink C API Documentation: MImage_getChannels
Sourcepub fn rank(&self) -> usize
pub fn rank(&self) -> usize
LibraryLink C API Documentation: MImage_getRank
Sourcepub fn row_count(&self) -> usize
pub fn row_count(&self) -> usize
LibraryLink C API Documentation: MImage_getRowCount
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
LibraryLink C API Documentation: MImage_getColumnCount
Sourcepub fn slice_count(&self) -> usize
pub fn slice_count(&self) -> usize
LibraryLink C API Documentation: MImage_getSliceCount
Sourcepub fn color_space(&self) -> ColorSpace
pub fn color_space(&self) -> ColorSpace
Get the color space of this image.
LibraryLink C API Documentation: MImage_getColorSpace
Sourcepub fn color_space_raw(&self) -> colorspace_t
pub fn color_space_raw(&self) -> colorspace_t
LibraryLink C API Documentation: MImage_getColorSpace
Sourcepub fn data_type_raw(&self) -> imagedata_t
pub fn data_type_raw(&self) -> imagedata_t
LibraryLink C API Documentation: MImage_getDataType
Sourcepub fn has_alpha_channel(&self) -> bool
pub fn has_alpha_channel(&self) -> bool
LibraryLink C API Documentation: MImage_alphaChannelQ
Sourcepub fn is_interleaved(&self) -> bool
pub fn is_interleaved(&self) -> bool
LibraryLink C API Documentation: MImage_interleavedQ
Returns the share count of this Image.
If this Image is not shared, the share count is 0.
If this Image was passed into the current library “by reference” due to
use of the Automatic or "Constant" memory management strategy, that reference
is not reflected in the share_count().
LibraryLink C API Documentation: MImage_shareCount
pub unsafe fn as_raw(&self) -> MImage
Sourcepub unsafe fn raw_data(&self) -> *mut c_void
pub unsafe fn raw_data(&self) -> *mut c_void
LibraryLink C API Documentation: MImage_getRawData