Spaces:
Running
Running
File size: 3,536 Bytes
347d1a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
"""
Constants for Sobel edge refinement algorithm.
This module contains all configurable parameters and thresholds used
in the edge refinement pipeline to make them easy to tune and maintain.
"""
# =============================================================================
# ROI Extraction Constants
# =============================================================================
# ROI padding around zone for gradient context
ROI_PADDING_PX = 50
# Finger width estimation factor (conservative to ensure full capture)
# Typical finger aspect ratio is 3:1 to 5:1 (length:width)
FINGER_WIDTH_RATIO = 3.0 # length / width
# =============================================================================
# Sobel Filter Constants
# =============================================================================
# Default Sobel kernel size
DEFAULT_KERNEL_SIZE = 3
# Valid kernel sizes
VALID_KERNEL_SIZES = [3, 5, 7]
# =============================================================================
# Edge Detection Constants
# =============================================================================
# Default gradient threshold for valid edge
DEFAULT_GRADIENT_THRESHOLD = 15.0
# Realistic finger width range for validation
# Based on typical adult finger widths across ring sizes
MIN_FINGER_WIDTH_CM = 1.6 # Size 6 (16mm)
MAX_FINGER_WIDTH_CM = 2.5 # Size 13 (23mm)
# Tolerance for expected width comparison (when contour available)
WIDTH_TOLERANCE_FACTOR = 0.25 # ±25%
# =============================================================================
# Sub-Pixel Refinement Constants
# =============================================================================
# Maximum sub-pixel refinement offset from integer position
MAX_SUBPIXEL_OFFSET = 0.5 # ±0.5 pixels
# Minimum denominator value to avoid division by zero in parabola fitting
MIN_PARABOLA_DENOMINATOR = 1e-6
# =============================================================================
# Outlier Filtering Constants
# =============================================================================
# MAD (Median Absolute Deviation) threshold multiplier
MAD_OUTLIER_THRESHOLD = 3.0 # Outliers are >3 MAD from median
# =============================================================================
# Edge Quality Scoring Constants
# =============================================================================
# Gradient strength normalization (typical strong edge magnitude)
GRADIENT_STRENGTH_NORMALIZER = 30.0
# Smoothness scoring (variance to exponential mapping)
SMOOTHNESS_VARIANCE_NORMALIZER = 200.0
# Quality score component weights
QUALITY_WEIGHT_GRADIENT = 0.4 # Gradient strength: 40%
QUALITY_WEIGHT_CONSISTENCY = 0.3 # Edge consistency: 30%
QUALITY_WEIGHT_SMOOTHNESS = 0.2 # Edge smoothness: 20%
QUALITY_WEIGHT_SYMMETRY = 0.1 # Bilateral symmetry: 10%
# =============================================================================
# Auto Fallback Decision Constants
# =============================================================================
# Minimum quality score to use Sobel (otherwise fall back to contour)
MIN_QUALITY_SCORE_THRESHOLD = 0.65 # Lowered from 0.7 for mask-constrained mode
# Minimum edge detection success rate
MIN_CONSISTENCY_THRESHOLD = 0.30 # 30% (lowered from 50% for mask-constrained mode)
# Realistic measurement range for validation
MIN_REALISTIC_WIDTH_CM = 0.8
MAX_REALISTIC_WIDTH_CM = 3.5
# Maximum allowed difference from contour measurement (percentage)
MAX_CONTOUR_DIFFERENCE_PCT = 50.0
|