Consistent formatting pass: line wrapping, import sorting, trailing whitespace removal, let-chain indentation, merged derive attributes, and unsafe block reformatting. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
133 lines
3.3 KiB
Rust
133 lines
3.3 KiB
Rust
//! Processing configuration for SlideScope
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Main processing configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
pub struct ProcessingConfig {
|
|
/// NMF configuration
|
|
pub nmf: NmfProcessingConfig,
|
|
/// Pyramid generation configuration
|
|
pub pyramid: PyramidProcessingConfig,
|
|
/// Stain estimation configuration
|
|
pub stain_estimation: StainEstimationConfig,
|
|
}
|
|
|
|
/// NMF processing configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct NmfProcessingConfig {
|
|
/// Number of stain components to extract
|
|
pub n_components: usize,
|
|
/// Maximum iterations for NMF
|
|
pub max_iterations: usize,
|
|
/// Convergence tolerance
|
|
pub tolerance: f32,
|
|
/// Use GPU acceleration if available
|
|
pub use_gpu: bool,
|
|
/// Random seed for reproducibility
|
|
pub random_seed: Option<u64>,
|
|
}
|
|
|
|
impl Default for NmfProcessingConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
n_components: 2,
|
|
max_iterations: 200,
|
|
tolerance: 1e-4,
|
|
use_gpu: true,
|
|
random_seed: Some(42),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl NmfProcessingConfig {
|
|
/// Fast config for testing
|
|
pub fn fast() -> Self {
|
|
Self {
|
|
n_components: 2,
|
|
max_iterations: 50,
|
|
tolerance: 1e-3,
|
|
use_gpu: false,
|
|
random_seed: Some(42),
|
|
}
|
|
}
|
|
|
|
/// Config for H&E staining (2 components)
|
|
pub fn he() -> Self {
|
|
Self {
|
|
n_components: 2,
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
/// Config for IHC-DAB staining (3 components)
|
|
pub fn ihc_dab() -> Self {
|
|
Self {
|
|
n_components: 3,
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Pyramid generation configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PyramidProcessingConfig {
|
|
/// Tile size in pixels
|
|
pub tile_size: u32,
|
|
/// Tile overlap in pixels
|
|
pub overlap: u32,
|
|
/// JPEG quality for tiles
|
|
pub jpeg_quality: u8,
|
|
/// Use parallel processing
|
|
pub parallel: bool,
|
|
}
|
|
|
|
impl Default for PyramidProcessingConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
tile_size: 256,
|
|
overlap: 0,
|
|
jpeg_quality: 85,
|
|
parallel: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Stain estimation configuration
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct StainEstimationConfig {
|
|
/// Estimation method to use
|
|
pub method: EstimationMethod,
|
|
/// Background intensity threshold (0.0-1.0)
|
|
pub background_threshold: f32,
|
|
/// Remove background pixels before estimation
|
|
pub remove_background: bool,
|
|
/// Number of samples to use for estimation
|
|
pub sample_size: Option<usize>,
|
|
}
|
|
|
|
impl Default for StainEstimationConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
method: EstimationMethod::Ruifrok,
|
|
background_threshold: 0.8,
|
|
remove_background: true,
|
|
sample_size: Some(10000),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Stain estimation methods
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
#[derive(Default)]
|
|
pub enum EstimationMethod {
|
|
/// Use pre-defined standard vectors (Ruifrok & Johnston)
|
|
#[default]
|
|
Ruifrok,
|
|
/// Macenko's method using SVD/PCA
|
|
Macenko,
|
|
/// Robust estimation combining multiple methods
|
|
Robust,
|
|
}
|