pub struct Image { /* private fields */ }Expand description
Dense pixels with explicit axis-order and channel-order semantics.
Image composes a Matrix instead of erasing its numeric dtype and
storage behavior. Construction validates all metadata once; the matrix is
thereafter exposed immutably so the image contract cannot be invalidated.
Implementations§
Source§impl Image
impl Image
Sourcepub fn new(
data: Matrix,
layout: ImageLayout,
format: ImageFormat,
) -> Result<Self>
pub fn new( data: Matrix, layout: ImageLayout, format: ImageFormat, ) -> Result<Self>
Attach checked image semantics to a dense matrix.
Zero-sized dimensions are legal. They remain useful for shape propagation and carry no special allocation promise beyond the backing matrix contract.
§Errors
Returns an error when the matrix rank does not match layout, the channel
axis does not match format, or an Hw image is assigned a non-gray
format.
Sourcepub const fn as_matrix(&self) -> &Matrix
pub const fn as_matrix(&self) -> &Matrix
Borrow the backing dense matrix without copying storage.
Sourcepub fn into_matrix(self) -> Matrix
pub fn into_matrix(self) -> Matrix
Remove image semantics and return the backing matrix.
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Return the batch extent, or one for an unbatched layout.
Sourcepub const fn layout(&self) -> ImageLayout
pub const fn layout(&self) -> ImageLayout
Return the image axis order.
Sourcepub const fn format(&self) -> ImageFormat
pub const fn format(&self) -> ImageFormat
Return the logical channel order.
Source§impl Image
impl Image
Sourcepub fn resize(
&self,
target_width: u32,
target_height: u32,
interpolation: InterpolationMode,
) -> Result<Self>
pub fn resize( &self, target_width: u32, target_height: u32, interpolation: InterpolationMode, ) -> Result<Self>
Resize an FP32 channel-first image while preserving its layout and format.
Delegates to crate::image::resize.
Sourcepub fn crop(&self, x: u32, y: u32, width: u32, height: u32) -> Result<Self>
pub fn crop(&self, x: u32, y: u32, width: u32, height: u32) -> Result<Self>
Extract a region, clipping its right and bottom edges to the source extent.
Delegates to crate::image::crop.
Sourcepub fn flip(&self, horizontal: bool, vertical: bool) -> Result<Self>
pub fn flip(&self, horizontal: bool, vertical: bool) -> Result<Self>
Flip an image horizontally, vertically, or along both axes.
Delegates to crate::image::flip.
Sourcepub fn rotate(&self, degrees: u32) -> Result<Self>
pub fn rotate(&self, degrees: u32) -> Result<Self>
Rotate clockwise by a multiple of 90 degrees.
Delegates to crate::image::rotate.
Sourcepub fn pad(
&self,
left: u32,
right: u32,
top: u32,
bottom: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn pad( &self, left: u32, right: u32, top: u32, bottom: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Add asymmetric padding with an explicit border policy.
Delegates to crate::image::pad.
Sourcepub fn center_crop(&self, width: u32, height: u32) -> Result<Self>
pub fn center_crop(&self, width: u32, height: u32) -> Result<Self>
Extract a centered region with the requested exact extent.
Delegates to crate::image::center_crop.
Sourcepub fn remap(
&self,
map: &Matrix,
interpolation: InterpolationMode,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn remap( &self, map: &Matrix, interpolation: InterpolationMode, border: BorderMode, border_value: f32, ) -> Result<Self>
Resample an image from an FP32 absolute-coordinate map shaped
Delegates to crate::image::remap.
Sourcepub fn warp_affine(
&self,
transform: &Matrix,
width: u32,
height: u32,
interpolation: InterpolationMode,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn warp_affine( &self, transform: &Matrix, width: u32, height: u32, interpolation: InterpolationMode, border: BorderMode, border_value: f32, ) -> Result<Self>
Apply an inverse FP32 2x3 affine transform to an image.
Delegates to crate::image::warp_affine.
Sourcepub fn warp_perspective(
&self,
transform: &Matrix,
width: u32,
height: u32,
interpolation: InterpolationMode,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn warp_perspective( &self, transform: &Matrix, width: u32, height: u32, interpolation: InterpolationMode, border: BorderMode, border_value: f32, ) -> Result<Self>
Apply an inverse FP32 3x3 perspective transform to an image.
Delegates to crate::image::warp_perspective.
Sourcepub fn threshold_binary(&self, threshold: f32, max_value: f32) -> Result<Self>
pub fn threshold_binary(&self, threshold: f32, max_value: f32) -> Result<Self>
Replace values above threshold with max_value and all others with zero.
Delegates to crate::image::threshold_binary.
Sourcepub fn threshold_binary_inv(
&self,
threshold: f32,
max_value: f32,
) -> Result<Self>
pub fn threshold_binary_inv( &self, threshold: f32, max_value: f32, ) -> Result<Self>
Replace values at or below threshold with max_value and all others with zero.
Delegates to crate::image::threshold_binary_inv.
Sourcepub fn threshold_truncate(&self, threshold: f32) -> Result<Self>
pub fn threshold_truncate(&self, threshold: f32) -> Result<Self>
Truncate values above threshold.
Delegates to crate::image::threshold_truncate.
Sourcepub fn threshold_to_zero(&self, threshold: f32) -> Result<Self>
pub fn threshold_to_zero(&self, threshold: f32) -> Result<Self>
Replace values at or below threshold with zero.
Delegates to crate::image::threshold_to_zero.
Sourcepub fn threshold_to_zero_inv(&self, threshold: f32) -> Result<Self>
pub fn threshold_to_zero_inv(&self, threshold: f32) -> Result<Self>
Replace values above threshold with zero.
Delegates to crate::image::threshold_to_zero_inv.
Sourcepub fn in_range(&self, low: f32, high: f32, true_value: f32) -> Result<Self>
pub fn in_range(&self, low: f32, high: f32, true_value: f32) -> Result<Self>
Produce true_value for values inside the inclusive interval and zero outside it.
Delegates to crate::image::in_range.
Sourcepub fn clamp(&self, low: f32, high: f32) -> Result<Self>
pub fn clamp(&self, low: f32, high: f32) -> Result<Self>
Clamp every pixel to the inclusive interval.
Delegates to crate::image::clamp.
Sourcepub fn invert(&self, max_value: f32) -> Result<Self>
pub fn invert(&self, max_value: f32) -> Result<Self>
Invert every value around max_value.
Delegates to crate::image::invert.
Sourcepub fn brightness_contrast(
&self,
brightness: f32,
contrast: f32,
) -> Result<Self>
pub fn brightness_contrast( &self, brightness: f32, contrast: f32, ) -> Result<Self>
Apply value * contrast + brightness.
Delegates to crate::image::brightness_contrast.
Sourcepub fn gamma_contrast(&self, gamma: f32, gain: f32) -> Result<Self>
pub fn gamma_contrast(&self, gamma: f32, gain: f32) -> Result<Self>
Apply max(value, 0)^gamma * gain.
Delegates to crate::image::gamma_contrast.
Sourcepub fn solarize(&self, threshold: f32, max_value: f32) -> Result<Self>
pub fn solarize(&self, threshold: f32, max_value: f32) -> Result<Self>
Invert values at or above threshold around max_value.
Delegates to crate::image::solarize.
Sourcepub fn posterize(&self, levels: u32, low: f32, high: f32) -> Result<Self>
pub fn posterize(&self, levels: u32, low: f32, high: f32) -> Result<Self>
Quantize [low, high] to levels evenly spaced values using round-half-up.
Delegates to crate::image::posterize.
Sourcepub fn grayscale(&self) -> Result<Self>
pub fn grayscale(&self) -> Result<Self>
Convert an RGB or RGBA image to Rec.709 grayscale.
Delegates to crate::image::grayscale.
Sourcepub fn alpha_blend(&self, right: &Image, alpha: f32) -> Result<Self>
pub fn alpha_blend(&self, right: &Image, alpha: f32) -> Result<Self>
Blend two equal semantic images using left * (1-alpha) + right * alpha.
Delegates to crate::image::alpha_blend.
Sourcepub fn composite(&self, right: &Image, mask: &Image) -> Result<Self>
pub fn composite(&self, right: &Image, mask: &Image) -> Result<Self>
Composite two equal images with a clamped Gray or per-channel mask.
Delegates to crate::image::composite.
Sourcepub fn erase(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
value: f32,
) -> Result<Self>
pub fn erase( &self, x: u32, y: u32, width: u32, height: u32, value: f32, ) -> Result<Self>
Fill the intersection of a rectangle and the image with one finite value.
Delegates to crate::image::erase.
Sourcepub fn color_twist(&self, transform: &Matrix) -> Result<Self>
pub fn color_twist(&self, transform: &Matrix) -> Result<Self>
Apply one shared FP32 [3, 4] affine color transform to RGB channels.
Delegates to crate::image::color_twist.
Sourcepub fn channel_reorder(
&self,
order: [u32; 4],
output_format: ImageFormat,
) -> Result<Self>
pub fn channel_reorder( &self, order: [u32; 4], output_format: ImageFormat, ) -> Result<Self>
Reorder one to four channels and explicitly assign the resulting format.
Delegates to crate::image::channel_reorder.
Sourcepub fn gaussian_noise(&self, mean: f32, stddev: f32, seed: u64) -> Result<Self>
pub fn gaussian_noise(&self, mean: f32, stddev: f32, seed: u64) -> Result<Self>
Add explicit-seed Philox Gaussian noise to every pixel.
Delegates to crate::image::gaussian_noise.
Sourcepub fn salt_pepper_noise(
&self,
probability: f32,
salt_value: f32,
pepper_value: f32,
seed: u64,
) -> Result<Self>
pub fn salt_pepper_noise( &self, probability: f32, salt_value: f32, pepper_value: f32, seed: u64, ) -> Result<Self>
Replace a seeded fraction of pixels with salt or pepper values.
Delegates to crate::image::salt_pepper_noise.
Sourcepub fn convolve_2d(
&self,
kernel: &Matrix,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn convolve_2d( &self, kernel: &Matrix, border: BorderMode, border_value: f32, ) -> Result<Self>
Apply same-shape 2D cross-correlation with an odd FP32 kernel up to 31×31.
Delegates to crate::image::convolve_2d.
Sourcepub fn separable_convolve_2d(
&self,
kernel_x: &Matrix,
kernel_y: &Matrix,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn separable_convolve_2d( &self, kernel_x: &Matrix, kernel_y: &Matrix, border: BorderMode, border_value: f32, ) -> Result<Self>
Apply horizontal and vertical odd FP32 vector kernels up to length 31.
Delegates to crate::image::separable_convolve_2d.
Sourcepub fn average_blur(
&self,
width: u32,
height: u32,
border: BorderMode,
) -> Result<Self>
pub fn average_blur( &self, width: u32, height: u32, border: BorderMode, ) -> Result<Self>
Average an odd rectangular neighborhood up to 31×31.
Delegates to crate::image::average_blur.
Sourcepub fn sobel(&self, dx: u32, dy: u32, border: BorderMode) -> Result<Self>
pub fn sobel(&self, dx: u32, dy: u32, border: BorderMode) -> Result<Self>
Compute one first-order Sobel derivative.
Delegates to crate::image::sobel.
Sourcepub fn scharr(&self, dx: u32, dy: u32, border: BorderMode) -> Result<Self>
pub fn scharr(&self, dx: u32, dy: u32, border: BorderMode) -> Result<Self>
Compute one first-order Scharr derivative.
Delegates to crate::image::scharr.
Sourcepub fn laplacian(&self, border: BorderMode) -> Result<Self>
pub fn laplacian(&self, border: BorderMode) -> Result<Self>
Apply the four-neighbor discrete Laplacian.
Delegates to crate::image::laplacian.
Sourcepub fn erode(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn erode( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Erode with an odd rectangular structuring element up to 31×31.
Delegates to crate::image::erode.
Sourcepub fn dilate(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn dilate( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Dilate with an odd rectangular structuring element up to 31×31.
Delegates to crate::image::dilate.
Sourcepub fn morphology_open(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn morphology_open( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Erode and then dilate with the same rectangular element.
Delegates to crate::image::morphology_open.
Sourcepub fn morphology_close(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn morphology_close( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Dilate and then erode with the same rectangular element.
Delegates to crate::image::morphology_close.
Sourcepub fn morphology_gradient(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn morphology_gradient( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Return dilation minus erosion.
Delegates to crate::image::morphology_gradient.
Sourcepub fn gaussian_blur(&self, sigma: f32, kernel_size: u32) -> Result<Self>
pub fn gaussian_blur(&self, sigma: f32, kernel_size: u32) -> Result<Self>
Apply a normalized Gaussian blur with replicate borders.
Delegates to crate::image::gaussian_blur.
Sourcepub fn sharpen(&self, amount: f32, border: BorderMode) -> Result<Self>
pub fn sharpen(&self, amount: f32, border: BorderMode) -> Result<Self>
Apply a nonnegative four-neighbor sharpening amount.
Delegates to crate::image::sharpen.
Sourcepub fn median_blur(&self, kernel_size: u32, border: BorderMode) -> Result<Self>
pub fn median_blur(&self, kernel_size: u32, border: BorderMode) -> Result<Self>
Select the median of an odd square neighborhood up to 15×15.
Delegates to crate::image::median_blur.
Sourcepub fn bilateral_filter(
&self,
kernel_size: u32,
sigma_color: f32,
sigma_space: f32,
border: BorderMode,
) -> Result<Self>
pub fn bilateral_filter( &self, kernel_size: u32, sigma_color: f32, sigma_space: f32, border: BorderMode, ) -> Result<Self>
Apply a bilateral neighborhood filter.
Delegates to crate::image::bilateral_filter.
Sourcepub fn unsharp_mask(
&self,
sigma: f32,
amount: f32,
kernel_size: u32,
) -> Result<Self>
pub fn unsharp_mask( &self, sigma: f32, amount: f32, kernel_size: u32, ) -> Result<Self>
Apply an unsharp mask using a Gaussian detail estimate.
Delegates to crate::image::unsharp_mask.
Sourcepub fn morphology_top_hat(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn morphology_top_hat( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Return the source minus its morphological opening.
Delegates to crate::image::morphology_top_hat.
Sourcepub fn morphology_black_hat(
&self,
width: u32,
height: u32,
border: BorderMode,
border_value: f32,
) -> Result<Self>
pub fn morphology_black_hat( &self, width: u32, height: u32, border: BorderMode, border_value: f32, ) -> Result<Self>
Return the morphological closing minus the source.
Delegates to crate::image::morphology_black_hat.
Sourcepub fn adaptive_threshold_mean(
&self,
kernel_size: u32,
c: f32,
max_value: f32,
border: BorderMode,
) -> Result<Self>
pub fn adaptive_threshold_mean( &self, kernel_size: u32, c: f32, max_value: f32, border: BorderMode, ) -> Result<Self>
Threshold against the local arithmetic mean minus c.
Delegates to crate::image::adaptive_threshold_mean.
Sourcepub fn adaptive_threshold_gaussian(
&self,
kernel_size: u32,
c: f32,
max_value: f32,
sigma: f32,
border: BorderMode,
) -> Result<Self>
pub fn adaptive_threshold_gaussian( &self, kernel_size: u32, c: f32, max_value: f32, sigma: f32, border: BorderMode, ) -> Result<Self>
Threshold against a local Gaussian-weighted mean minus c.
Delegates to crate::image::adaptive_threshold_gaussian.
Sourcepub fn normalize(&self, parameters: NormalizationConfig) -> Result<Self>
pub fn normalize(&self, parameters: NormalizationConfig) -> Result<Self>
Apply (pixel - mean[channel]) / std[channel] to up to three channels.
Delegates to crate::image::normalize.
Sourcepub fn convert_color(&self, destination_format: ImageFormat) -> Result<Self>
pub fn convert_color(&self, destination_format: ImageFormat) -> Result<Self>
Convert between three-channel RGB and BGR semantics, including identity.
Delegates to crate::image::convert_color.
Sourcepub fn resize_normalize(
&self,
width: u32,
height: u32,
parameters: NormalizationConfig,
) -> Result<Self>
pub fn resize_normalize( &self, width: u32, height: u32, parameters: NormalizationConfig, ) -> Result<Self>
Bilinearly resize and normalize in one semantic and executable operation.
Delegates to crate::image::resize_normalize.
Sourcepub fn segmentation_overlay(
&self,
mask: &Matrix,
palette: &Matrix,
alpha: f32,
) -> Result<Self>
pub fn segmentation_overlay( &self, mask: &Matrix, palette: &Matrix, alpha: f32, ) -> Result<Self>
Blend a class palette over an RGB/RGBA image using an I32 label map.
Delegates to crate::image::segmentation_overlay.
Sourcepub fn calc_hist(&self, bins: u32, lower: f32, upper: f32) -> Result<Matrix>
pub fn calc_hist(&self, bins: u32, lower: f32, upper: f32) -> Result<Matrix>
Accumulate a per-plane histogram over an FP32 NCHW or CHW image.
Delegates to crate::image::calc_hist.
Sourcepub fn equalize_hist(&self) -> Result<Self>
pub fn equalize_hist(&self) -> Result<Self>
Equalize a normalized FP32 image histogram per (batch, channel) plane.
Delegates to crate::image::equalize_hist.