Skip to main content

PatchExtractor

Struct PatchExtractor 

Source
pub struct PatchExtractor { /* private fields */ }
Expand description

Patch Extractor with Builder Pattern

A configurable patch extractor that provides a clean interface for patch extraction with various sampling strategies and optimization options.

§Builder Pattern

The extractor uses the builder pattern for clean configuration:

  • Chainable method calls for easy setup
  • Sensible defaults for quick usage
  • Comprehensive validation of parameters

§Configuration Options

  • Patch Size: Dimensions of extracted patches
  • Max Patches: Limit on number of patches to extract
  • Random State: Seed for reproducible random sampling
  • Sampling Strategy: How to select patch positions

§Examples

use sklears_feature_extraction::image::patch_extraction::PatchExtractor;
use scirs2_core::ndarray::Array2;

let image = Array2::from_shape_vec((10, 10), (0..100).map(|x| x as f64).collect()).expect("shape and data length match");
let extractor = PatchExtractor::new()
    .patch_size((3, 3))
    .max_patches(Some(10))
    .random_state(Some(42));
let patches = extractor.extract(&image.view()).expect("valid image and extractor config produce patches");

Implementations§

Source§

impl PatchExtractor

Source

pub fn new() -> Self

Create a new PatchExtractor with default settings

Default configuration:

  • Patch size: 8x8 pixels
  • Max patches: None (extract all)
  • Random state: None (non-deterministic)
  • Sampling: UniformGrid
Source

pub fn patch_size(self, patch_size: (usize, usize)) -> Self

Set the patch size

§Parameters
  • patch_size - Dimensions of patches as (height, width)
§Panics

Panics if either dimension is zero

Source

pub fn max_patches(self, max_patches: Option<usize>) -> Self

Set the maximum number of patches to extract

§Parameters
  • max_patches - Maximum patches (None for all possible)
Source

pub fn random_state(self, random_state: Option<u64>) -> Self

Set the random state for reproducible sampling

§Parameters
  • random_state - Random seed (None for non-deterministic)
Source

pub fn sampling_strategy(self, strategy: SamplingStrategy) -> Self

Set the sampling strategy

§Parameters
  • strategy - Sampling strategy to use
Source

pub fn extract(&self, image: &ArrayView2<'_, Float>) -> SklResult<Array3<Float>>

Extract patches from image using configured settings

§Parameters
  • image - Input 2D image to extract patches from
§Returns

3D array of extracted patches

Source

pub fn summary(&self) -> String

Get the current configuration summary

§Returns

Configuration parameters as formatted string

Trait Implementations§

Source§

impl Clone for PatchExtractor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PatchExtractor

Source§

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

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

impl Default for PatchExtractor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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