A comprehensive pipeline for solving square jigsaw puzzles using computer vision and machine learning techniques. The system now implements three complementary approaches optimized for different grid sizes:
- Descriptor-Based Algorithm (custom, feature-rich) - for 2×2 puzzles
- Advanced Solver Algorithm (MSE-based with multi-feature analysis) - for 4×4 and 8×8 puzzles
- Paper-Based Algorithm inspired by Pomeranz et al., 2011
All approaches are enhanced with advanced preprocessing, robust matching strategies, and detailed visualization tools.
- 2×2 puzzles: Uses
DescriptorBasedAssemblerwith MSE-based edge comparison - 4×4 and 8×8 puzzles: Uses
AdvancedPuzzleSolverwith sophisticated feature analysis - Automatic grid detection based on filenames (2x2, 4x4, 8x8)
- LAB color space for perceptually uniform color comparison
- Multi-feature border analysis: Color + Gradient Magnitude + Gradient Direction + Laplacian edges
- Weighted distance metrics with configurable importance weights
- Border standardization and reorientation for consistent comparison
- Modular design with separate modules for different functionalities
- Better error handling and validation
- Organized output structure with dedicated folders for each puzzle type
The system follows a modular, multi-stage pipeline, designed for robustness and extensibility.
- ZIP file containing puzzle images
- Supported grid sizes: 2×2, 4×4, 8×8 (auto-detected)
- Automatic ZIP extraction with directory preservation
- Images organized based on directory and filename structure
- Dynamic noise level estimation per image using Laplacian variance
- Noise variance used to control denoising intensity
- Adaptive median filtering only when noise > 150 variance
- Applied only to high-noise regions (threshold-based masking)
- Preserves critical edge and boundary information
- CLAHE (Contrast Limited Adaptive Histogram Equalization) - Local contrast enhancement
- Luminance-channel sharpening - Detail preservation
- Gamma correction (γ=0.9) - Global lightness control
- Canny edge detection - Boundary analysis
- Automatic detection from filename and directory patterns
- Pattern matching: "2x2", "4x4", "8x8" in filenames
- Uniform division into N×N grid
- Consistent piece dimensions across all puzzles
- Border extraction: 3-pixel wide borders (configurable)
- Multi-feature representation:
- Color features: LAB color space (3 channels)
- Gradient magnitude: Sobel-based edge strength
- Gradient direction: Edge orientation (0-360°)
- Edge response: Laplacian edge detection
- Feature standardization: Mean=0, STD=1 normalization
- MSE-based edge comparison
- LAB + gradient + laplacian features
- Brute-force search for 2×2 permutations
- Compatibility scoring with confidence margins
- Border feature extraction for all pieces and sides
- Compatibility matrix generation:
- Top-Bottom compatibility
- Right-Left compatibility
- Bottom-Top compatibility
- Left-Right compatibility
- Reciprocal best match verification
- Greedy assembly with prioritization:
- Prioritize reciprocal matches
- Weighted compatibility scores
- Position-based optimization
- All permutations evaluation (4! = 24 possibilities)
- Total cost calculation for each arrangement
- Confidence margin computation (gap between best and second-best)
- Before/After examples with metrics
- Grid cutting visualization with piece numbering
- Heatmaps for horizontal and vertical match scores
- Top matches display with connecting lines
- Final assembly with quality score