pub struct ImageFeatureSelector<State = Untrained> { /* private fields */ }Expand description
Image feature selection using spatial correlation and frequency analysis
This selector analyzes image features represented as flattened pixel matrices or extracted feature vectors and applies image-specific selection criteria:
- Spatial correlation analysis for neighboring pixels
- Frequency domain analysis using variance as a proxy
- Texture analysis using local variance measurements
- Combined scoring with target correlation
§Input Format
The input matrix X should be structured as:
- Rows: Images
- Columns: Features (pixels, extracted features, etc.)
- Values: Pixel intensities, feature values, or derived measurements
§Examples
use sklears_feature_selection::domain_specific::image_features::ImageFeatureSelector;
use sklears_core::traits::{Fit, Transform};
use scirs2_core::ndarray::{Array1, Array2};
let selector = ImageFeatureSelector::new()
.include_spatial(true) // Enable spatial correlation analysis
.include_frequency(true) // Enable frequency domain analysis
.include_texture(true) // Enable texture analysis
.spatial_threshold(0.15) // Threshold for spatial features
.k(Some(100)); // Select top 100 features
let x = Array2::zeros((50, 784)); // 50 images, 784 pixels (28x28)
let y = Array1::zeros(50); // Image labels
let fitted_selector = selector.fit(&x, &y)?;
let transformed_x = fitted_selector.transform(&x)?;Implementations§
Source§impl ImageFeatureSelector<Untrained>
impl ImageFeatureSelector<Untrained>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new image feature selector with default parameters
Default configuration:
include_spatial: trueinclude_frequency: trueinclude_texture: truespatial_threshold: 0.1k: None (use threshold-based selection)
Sourcepub fn include_spatial(self, include_spatial: bool) -> Self
pub fn include_spatial(self, include_spatial: bool) -> Self
Enable or disable spatial correlation analysis
When enabled, the selector computes correlations between features and the target variable, emphasizing spatial relationships.
Sourcepub fn include_frequency(self, include_frequency: bool) -> Self
pub fn include_frequency(self, include_frequency: bool) -> Self
Enable or disable frequency domain analysis
When enabled, the selector analyzes frequency content using variance as a proxy for spectral energy, combined with target correlation.
Sourcepub fn include_texture(self, include_texture: bool) -> Self
pub fn include_texture(self, include_texture: bool) -> Self
Enable or disable texture analysis
When enabled, the selector computes local variance measurements to identify texture-rich regions that correlate with the target.
Sourcepub fn spatial_threshold(self, threshold: f64) -> Self
pub fn spatial_threshold(self, threshold: f64) -> Self
Set the threshold for spatial correlation selection
Features with combined scores below this threshold will be filtered out (when not using k-based selection).
Source§impl ImageFeatureSelector<Trained>
impl ImageFeatureSelector<Trained>
Sourcepub fn spatial_scores(&self) -> Option<&Array1<Float>>
pub fn spatial_scores(&self) -> Option<&Array1<Float>>
Get the spatial correlation scores (if spatial analysis was enabled)
Returns None if spatial analysis was not enabled during fitting.
Sourcepub fn frequency_scores(&self) -> Option<&Array1<Float>>
pub fn frequency_scores(&self) -> Option<&Array1<Float>>
Get the frequency domain scores (if frequency analysis was enabled)
Returns None if frequency analysis was not enabled during fitting.
Sourcepub fn texture_scores(&self) -> Option<&Array1<Float>>
pub fn texture_scores(&self) -> Option<&Array1<Float>>
Get the texture scores (if texture analysis was enabled)
Returns None if texture analysis was not enabled during fitting.
Sourcepub fn selected_features(&self) -> &[usize]
pub fn selected_features(&self) -> &[usize]
Get the indices of selected features
Sourcepub fn n_features_selected(&self) -> usize
pub fn n_features_selected(&self) -> usize
Get the number of selected features
Sourcepub fn feature_summary(
&self,
) -> Vec<(usize, Option<Float>, Option<Float>, Option<Float>)>
pub fn feature_summary( &self, ) -> Vec<(usize, Option<Float>, Option<Float>, Option<Float>)>
Get a summary of feature scores across all analysis types
Returns a vector of tuples containing (feature_index, spatial_score, frequency_score, texture_score)
for all selected features. Scores are None if the corresponding analysis was not enabled.
Trait Implementations§
Source§impl<State: Clone> Clone for ImageFeatureSelector<State>
impl<State: Clone> Clone for ImageFeatureSelector<State>
Source§fn clone(&self) -> ImageFeatureSelector<State>
fn clone(&self) -> ImageFeatureSelector<State>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<State: Debug> Debug for ImageFeatureSelector<State>
impl<State: Debug> Debug for ImageFeatureSelector<State>
Source§impl Default for ImageFeatureSelector<Untrained>
impl Default for ImageFeatureSelector<Untrained>
Source§impl Estimator for ImageFeatureSelector<Untrained>
impl Estimator for ImageFeatureSelector<Untrained>
Source§type Error = SklearsError
type Error = SklearsError
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>> for ImageFeatureSelector<Untrained>
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>> for ImageFeatureSelector<Untrained>
Source§type Fitted = ImageFeatureSelector<Trained>
type Fitted = ImageFeatureSelector<Trained>
Source§fn fit(self, x: &Array2<Float>, y: &Array1<Float>) -> SklResult<Self::Fitted>
fn fit(self, x: &Array2<Float>, y: &Array1<Float>) -> SklResult<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Source§impl SelectorMixin for ImageFeatureSelector<Trained>
impl SelectorMixin for ImageFeatureSelector<Trained>
Auto Trait Implementations§
impl<State> Freeze for ImageFeatureSelector<State>
impl<State> RefUnwindSafe for ImageFeatureSelector<State>where
State: RefUnwindSafe,
impl<State> Send for ImageFeatureSelector<State>where
State: Send,
impl<State> Sync for ImageFeatureSelector<State>where
State: Sync,
impl<State> Unpin for ImageFeatureSelector<State>where
State: Unpin,
impl<State> UnwindSafe for ImageFeatureSelector<State>where
State: 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<T> StableApi for Twhere
T: Estimator,
impl<T> StableApi for Twhere
T: Estimator,
Source§const STABLE_SINCE: &'static str = "0.1.0"
const STABLE_SINCE: &'static str = "0.1.0"
Source§const HAS_EXPERIMENTAL_FEATURES: bool = false
const HAS_EXPERIMENTAL_FEATURES: bool = false
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.