pub struct PineappleBuffer<T, Container> {
pub buffer: Container,
/* private fields */
}Expand description
A row-major container storing an image buffer or grid of pixels.
The struct is generic over the data type T and over the container that
holds raw pixel/subpixel data as a slice ([T]) or vector (Vec<T>).
The container holding the pixel data must implement Deref<Target = [T]>
to allow for slice-like access to the data. The length of the container
must also be equal to the product of w * h * c.
§Examples
use pineapple_core::im::PineappleBuffer;
let width = 10;
let height = 10;
let channels = 3; // RGB
let data = vec![0u8; (width * height * channels) as usize];
let buffer = PineappleBuffer::new(width, height, channels, data);
assert_eq!(buffer.unwrap().len(), (width * height * channels) as usize);use pineapple_core::im::PineappleBuffer;
let width = 10;
let height = 10;
let channels = 3; // RGB
let data = vec![0u8; (width * height * 3 * channels) as usize];
let buffer = PineappleBuffer::new(width, height, channels, data);
assert!(buffer.is_err()); // Buffer size does not match dimensionsFields§
§buffer: ContainerImplementations§
Source§impl<T, Container> PineappleBuffer<T, Container>
impl<T, Container> PineappleBuffer<T, Container>
Sourcepub fn new(
width: u32,
height: u32,
channels: u32,
buffer: Container,
) -> Result<PineappleBuffer<T, Container>, PineappleError>
pub fn new( width: u32, height: u32, channels: u32, buffer: Container, ) -> Result<PineappleBuffer<T, Container>, PineappleError>
Initializes a buffer from a generic data container
§Arguments
width- Image widthheight- Image heightchannels- Number of image channels (e.g. 1 for grayscale)buffer- A generic container (e.g.Vecor slice)
§Examples
use pineapple_core::im::PineappleBuffer;
let buffer = [0, 1, 2, 3, 4];
let buffer = PineappleBuffer::new(2, 2, 1, buffer.as_slice());Source§impl<T, Container> PineappleBuffer<T, Container>
impl<T, Container> PineappleBuffer<T, Container>
Source§impl<T, Container> PineappleBuffer<T, Container>
impl<T, Container> PineappleBuffer<T, Container>
Sourcepub fn as_raw(&self) -> &Container
pub fn as_raw(&self) -> &Container
Returns a reference to the raw image
pub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter_channel( &self, channel: u32, ) -> Result<impl Iterator<Item = &T>, PineappleError>
pub fn iter_pixels(&self) -> ChunksExact<'_, T>
Source§impl<T, Container> PineappleBuffer<T, Container>
impl<T, Container> PineappleBuffer<T, Container>
Sourcepub fn crop_view(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
) -> PineappleViewBuffer<'_, T, Container>
pub fn crop_view( &self, x: u32, y: u32, w: u32, h: u32, ) -> PineappleViewBuffer<'_, T, Container>
Generate a zero-copy crop of an image subregion
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of crop
Sourcepub fn crop(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
) -> Result<PineappleBuffer<T, Container>, PineappleError>
pub fn crop( &self, x: u32, y: u32, w: u32, h: u32, ) -> Result<PineappleBuffer<T, Container>, PineappleError>
Create a new buffer with copied cropped contents
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of crop
Sourcepub fn crop_masked(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
mask: &PineappleMaskView<'_>,
mask_style: MaskingStyle,
) -> Result<PineappleBuffer<T, Container>, PineappleError>
pub fn crop_masked( &self, x: u32, y: u32, w: u32, h: u32, mask: &PineappleMaskView<'_>, mask_style: MaskingStyle, ) -> Result<PineappleBuffer<T, Container>, PineappleError>
Crops the buffer while applying a mask to either foreground or background pixels
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of cropmask- A cropped mask viewmask_style- Foreground or background masking style
Source§impl PineappleBuffer<u32, Vec<u32>>
impl PineappleBuffer<u32, Vec<u32>>
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<PineappleMask, PineappleError>
pub fn open<P: AsRef<Path>>(path: P) -> Result<PineappleMask, PineappleError>
Open a new mask from a provided path
§Arguments
path- A path to an image with a valid extension
use pineapple_core::im::PineappleMask;
let image = PineappleMask::open("mask.png");Sourcepub fn new_from_dynamic(
mask: DynamicImage,
) -> Result<PineappleMask, PineappleError>
pub fn new_from_dynamic( mask: DynamicImage, ) -> Result<PineappleMask, PineappleError>
Initialize a new mask from a DynamicImage
§Arguments
image- An 8 or 16-bit grayscale DynamicImage
§Examples
use image::{GrayImage, DynamicImage};
use pineapple_core::im::PineappleMask;
let gray = GrayImage::new(10, 10);
let dynamic = DynamicImage::ImageLuma8(gray);
let image = PineappleMask::new_from_dynamic(dynamic);Sourcepub fn new_from_numpy(
npy: NpyFile<&[u8]>,
) -> Result<PineappleMask, PineappleError>
pub fn new_from_numpy( npy: NpyFile<&[u8]>, ) -> Result<PineappleMask, PineappleError>
Initialize a new image from a numpy array buffer
§Arguments
npy- A (height, width, channel) shaped numpy array buffer
§Examples
use npyz::NpyFile;
use pineapple_core::im::PineappleMask;
let bytes = std::fs::read("mask.npy").unwrap();
let npy = NpyFile::new(&bytes[..]).unwrap();
let image = PineappleMask::new_from_numpy(npy);Source§impl PineappleBuffer<u32, Vec<u32>>
impl PineappleBuffer<u32, Vec<u32>>
Sourcepub fn label(&mut self) -> Vec<u32>
pub fn label(&mut self) -> Vec<u32>
Re-label the mask using connected components and return unique labels
§Notes
Re-labelling is guaranteed to assign the correct number of labels when assuming 8-connectivity. However, the labels are not guaranteed to be incremental (e.g. 1, 2, 3, ..). This should be taken into account when iterating over objects.
Sourcepub fn polygons(&mut self) -> Result<(Vec<u32>, Polygons), PineappleError>
pub fn polygons(&mut self) -> Result<(Vec<u32>, Polygons), PineappleError>
Extract polygons from a segmentation mask
Sourcepub fn crop_binary(
&self,
x: u32,
y: u32,
w: u32,
h: u32,
label: u32,
) -> Result<PineappleMask, PineappleError>
pub fn crop_binary( &self, x: u32, y: u32, w: u32, h: u32, label: u32, ) -> Result<PineappleMask, PineappleError>
Crops image while only including pixels with a specified label
§Arguments
x- Minimum x-coordinate (left)y- Minimum y-coordinate (bottom)w- Width of croph- Height of croplabel- Only include mask pixels equal to this label
Trait Implementations§
Source§impl<T: Clone, Container: Clone> Clone for PineappleBuffer<T, Container>
impl<T: Clone, Container: Clone> Clone for PineappleBuffer<T, Container>
Source§fn clone(&self) -> PineappleBuffer<T, Container>
fn clone(&self) -> PineappleBuffer<T, Container>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<T, Container> Freeze for PineappleBuffer<T, Container>where
Container: Freeze,
impl<T, Container> RefUnwindSafe for PineappleBuffer<T, Container>where
Container: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Container> Send for PineappleBuffer<T, Container>
impl<T, Container> Sync for PineappleBuffer<T, Container>
impl<T, Container> Unpin for PineappleBuffer<T, Container>
impl<T, Container> UnwindSafe for PineappleBuffer<T, Container>where
Container: UnwindSafe,
T: UnwindSafe,
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.