A comprehensive toolkit for evaluating print/scan job processing by comparing original and processed document images.
You need a virtual PDF printer that saves output to files instead of physical printing.
# Install cups-pdf
sudo dnf install cups-pdf
# This creates a printer queue named "Cups-PDF"
# Verify it exists:
lpstat -p Cups-PDF
# Output: printer Cups-PDF is idle
# Output files will be saved in: ~/Desktop/# Install cups-pdf
sudo apt install cups-pdf
# For Ubuntu 25.10 and later, use:
sudo apt install printer-driver-cups-pdf
# Reload systemd to recognize the new printer
sudo systemctl daemon-reload
# This creates a printer queue named "PDF"
# Verify it exists:
lpstat -p PDF
# Output: printer PDF is idle
# Output files will be saved in: ~/PDF/Note for Ubuntu 25.10 users: The package is printer-driver-cups-pdf (not cups-pdf).
# List all available printers
lpstat -p
# Common names:
# - "Cups-PDF" (Fedora/RHEL with cups-pdf)
# - "PDF" (Ubuntu/Debian with cups-pdf)
# - "Virtual_PDF_Printer" (custom manual setup)Important: Use your actual printer queue name in the commands below. Replace Cups-PDF with your printer name (e.g., PDF on Ubuntu).
New to this project? Start here for instant impressive results:
# Use your printer queue name
python print_quality_pipeline.py Cups-PDF # Fedora/RHEL
# OR
python print_quality_pipeline.py PDF # Ubuntu/Debian
# See quality scores, visual differences, problem detection# Use your printer queue name
python filter_chain_test_pipeline.py Cups-PDF
# X-ray vision: see what each filter does to your documentpython test_document_pipeline.py
# Test 15+ document types, get comprehensive quality reportpython example_usage.py
# Explore 11 advanced image analysis algorithms📚 Complete HOWTOs with examples →
✅ Verify everything works: python verify_setup.py
This project implements automated testing for print quality assurance by evaluating images before and after processing through a print pipeline. It uses computer vision and image processing techniques to detect differences, verify text preservation, and ensure proper rendering of graphical elements.
The system supports extensive testing with various document types including text in different languages, multiple fonts, images, and complex layouts. Results are presented in detailed reports with visual comparison tools.
-
Comprehensive Image Comparison
- SSIM (Structural Similarity Index) analysis
- Feature detection and matching using ORB
- Edge detection and comparison
- Color fidelity analysis with histogram comparison and Delta-E metrics
- Visual difference heatmaps
- Edge quality analysis with multi-scale edge detection
- Advanced algorithms: density detection, rotation analysis, noise analysis, texture analysis, and geometric analysis
-
Page Integrity Verification
- Multi-page document processing
- Page completeness verification
- Page order validation
- Missing and duplicate page detection
- Page-by-page quality comparison
-
Text Preservation Testing
- OCR-based text extraction
- Text similarity analysis
- Font rendering verification
-
Diverse Test Documents
- Text in multiple languages (English, Spanish, French, German, etc.)
- Various fonts and sizes
- Pure image documents
- Mixed content (text and images)
- Complex layouts with tables and columns
- Multi-page documents with orientation variations
-
Detailed Reporting
- HTML reports with visual comparisons
- CSV summary files
- JSON result data for each test
- Pass/fail determination based on customizable thresholds
- Visual page integrity maps for multi-page documents
test_pipeline.py: Basic single-document test pipelinetest_document_pipeline.py: Comprehensive testing with multiple document typesmultipage_test.py: Multi-page document testing with page integrity verificationprint_quality_pipeline.py: Complete end-to-end print quality testing pipelinefilter_chain_test_pipeline.py: Isolated CUPS filter chain correctness testingenhanced_comparison.py: Advanced image comparison techniquesprinter_info.py: CUPS filter chain analysis and execution
generate_pdf.py: Simple PDF generation for basic testsgenerate_test_documents.py: Creates a variety of test documents including multi-page with page markers
extract_text.py: Standalone tool for OCR text extractioncompare_image.py: Simple image comparison utilityclean_workspace.py: Python script for cleaning the workspacecleanup.sh: User-friendly shell wrapper for cleanup operations
For Ubuntu/Debian users, it's recommended to use a virtual environment:
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install all required Python packages
pip install -r requirements.txt
# Note: If you get an error about 'cups' module, uninstall the wrong package:
pip uninstall cups
pip install pycupsFor Fedora/RHEL users:
pip install -c requirements.txtImportant: Make sure to install pycups (not cups). The cups package from pip conflicts with the required pycups library.
Additionally, ensure you have the following system packages:
- Ghostscript (for PDF to image conversion)
- CUPS (for print processing)
- Tesseract OCR (for text extraction)
- cups-filters (for accessing CUPS filter components)
- printer-driver-cups-pdf (Ubuntu) or cups-pdf (Fedora)
To run a basic test with a simple document:
python test_pipeline.pyThis will:
- Generate a simple PDF
- Process it through the print pipeline
- Compare the original and processed versions
- Display similarity metrics
- Extract and compare text
For complete end-to-end print quality assessment:
python print_quality_pipeline.pyThis comprehensive pipeline will:
- Automatic Printer Detection: Discover available CUPS printers and their capabilities
- Test Document Generation: Create diverse test images with various characteristics (text, images, patterns, colors)
- Filter Chain Analysis: Analyze and display the complete CUPS filter chain for each printer
- Automated Processing: Process all test documents through each detected printer
- Advanced Comparison: Apply comprehensive image analysis algorithms including:
- SSIM and feature matching
- Edge quality analysis
- Color fidelity assessment
- Density and texture analysis
- Rotation and geometric distortion detection
- Noise analysis
- Detailed Reporting: Generate HTML reports with visual comparisons and quantitative metrics
- Quality Scoring: Provide overall quality scores and pass/fail determinations
Use Cases:
- Production print quality validation
- Printer performance benchmarking
- Comprehensive quality assurance testing
- Print system validation across multiple printers
For testing CUPS filter chain correctness without physical printing:
python filter_chain_test_pipeline.pyThis specialized pipeline will:
- Filter Chain Isolation: Test CUPS filter processing independent of physical hardware
- Systematic Test Image Generation: Create targeted test images for specific filter scenarios:
- Pure text documents
- High-resolution images
- Color and grayscale content
- Various DPI settings
- Complex layouts
- Direct Filter Processing: Process images through CUPS filters without physical printing
- Digital Comparison: Compare filter outputs using pixel-perfect analysis
- Filter-Specific Validation: Identify issues specific to individual filters in the chain
- Regression Testing: Detect filter processing changes between CUPS versions
Use Cases:
- CUPS filter development and debugging
- Filter chain regression testing
- Digital print processing validation
- Isolating software issues from hardware problems
- CI/CD integration for CUPS testing
For testing with multiple document types:
python test_document_pipeline.pyThis will:
- Generate various test documents
- Process each document through the print pipeline
- Perform detailed comparison of each document
- Generate an HTML report with results
For testing multi-page documents with page integrity verification:
python multipage_test.pyThis will:
- Generate multi-page test documents
- Process documents through the print pipeline
- Extract and compare individual pages
- Check for missing or reordered pages
- Generate visualizations of page mapping and quality metrics
To test and demonstrate the image processing algorithms:
python test_algorithms.pyThis will:
- Generate test images with various characteristics
- Run all implemented algorithms (density, rotation, noise, texture, geometric)
- Display quantitative results for each algorithm
- Generate visualization outputs for analysis
For a practical example with existing images:
python example_usage.pyTo analyze and test CUPS filter chains:
>>> from printer_info import get_filter_chain, run_cups_filter_chain, get_comprehensive_printer_info, get_available_printers
>>> printers = get_available_printers()
>>> printer_name = printers[0]
>>> get_comprehensive_printer_info(printer_name) # View detailed printer information
>>> filter_chain = get_filter_chain(printer_name, input_mime_type='application/pdf') # Identify filter chain
>>> print(filter_chain)
>>> # Test a filter chain with direct execution:
>>> run_cups_filter_chain(
... printer_name=printer_name,
... input_file_path="sample.pdf",
... output_file_path="output_raster.data",
... custom_filters=['pdftopdf', 'pdftoraster'],
... filter_options={'pdftoraster': 'ColorModel=RGB Resolution=300'}
... )After testing, clean up your workspace:
# Using the shell script (interactive)
./cleanup.sh
# Common operations
./cleanup.sh quick # Remove temporary files
./cleanup.sh full # Full cleanup (keep reports)
./cleanup.sh backup # Backup reports then clean
# Direct Python usage
python clean_workspace.py --temp-files --keep-reportsBest for:
- Production print quality validation
- Testing complete printing systems (software + hardware)
- Benchmarking printer performance
- Real-world print quality assessment
- Testing with physical printers and scanners
What it tests:
- Complete print-to-paper-to-scan workflow
- Hardware-specific rendering quality
- Paper and ink interactions
- Scanner quality and calibration
- End-to-end system performance
Output: Physical print quality metrics with real-world variability
Best for:
- CUPS filter development and debugging
- Software-only testing without hardware dependencies
- Regression testing for CUPS updates
- CI/CD integration
- Isolating filter chain issues from hardware problems
What it tests:
- Pure digital filter processing accuracy
- CUPS software pipeline correctness
- Filter chain configuration validation
- Pixel-perfect digital processing
- Software regression detection
Output: Precise digital processing validation with minimal variability
- Adjust quality thresholds in the test scripts
- Modify document generation in
generate_test_documents.py - Add new comparison techniques in
enhanced_comparison.py - Update page integrity detection parameters in the
page_integrity_comparisonmethod
├── test_pipeline.py # Basic testing pipeline
├── test_document_pipeline.py # Comprehensive testing
├── multipage_test.py # Multi-page document testing
├── print_quality_pipeline.py # Complete end-to-end print quality testing
├── filter_chain_test_pipeline.py # CUPS filter chain correctness testing
├── enhanced_comparison.py # Advanced image comparison
├── test_algorithms.py # Test script for image processing algorithms
├── test_color_detection.py # Test script specifically for color/monochrome detection
├── example_usage.py # Example usage of image processing algorithms
├── generate_pdf.py # Basic PDF generation
├── generate_test_documents.py # Test document creation
├── extract_text.py # OCR utility
├── compare_image.py # Basic image comparison
├── clean_workspace.py # Cleanup utility
├── cleanup.sh # Shell wrapper for cleanup
├── printer_info.py # CUPS filter chain analysis and testing
├── PDF/ # Output directory for CUPS
└── test_documents/ # Generated during testing
├── *.pdf # Test documents
├── *.png # Rendered images
├── *_results.json # Individual test results
├── test_summary.csv # Results summary
├── test_report.html # Visual HTML report
└── multipage/ # Multi-page test results
├── complete_doc/ # Complete document results
├── reordered/ # Reordered page tests
└── missing/ # Missing page tests
The edge quality analysis uses multi-scale edge detection to evaluate how well fine details and contours are preserved in the printing process. This helps identify issues with:
- Loss of fine details
- Edge blurring or sharpening
- Contour discontinuities
- Line width variations
The page integrity verification system analyzes multi-page documents to detect common errors:
- Missing pages
- Duplicated pages
- Reordered pages
- Page orientation errors
The system uses feature matching to identify corresponding pages regardless of minor distortions and generates visualizations showing page mapping between reference and processed documents.
The filter chain analysis system provides a way to inspect, understand, and test the exact sequence of filters that CUPS would use for a specific printer and document type:
- Filter Chain Detection: Query the filters that would be used based on printer PPD configurations
- Direct Filter Execution: Manually control and test specific filter sequences for precise debugging
- Troubleshooting Tools: Compare output from different filters to isolate issues in complex print pipelines
- Printer Information Collection: Gather comprehensive details about available printers and their capabilities
- PPD Analysis: Extract filter information directly from printer PPD files when needed
The filter_chain_test_pipeline.py provides specialized testing focused on CUPS filter processing accuracy:
Key Features:
- Hardware-Independent Testing: Tests filter chains without requiring physical printers or scanners
- Systematic Test Generation: Creates targeted test images designed to reveal specific filter processing issues
- Digital Precision: Performs pixel-perfect comparisons without hardware-induced variations
- Filter Isolation: Identifies which specific filters in a chain may be causing processing problems
- Automated Test Suite: Runs comprehensive tests across multiple document types and configurations
Test Categories:
- Text Rendering: Validates text processing and font rendering accuracy
- Image Processing: Tests color space conversion, resolution scaling, and image compression
- Layout Preservation: Ensures document structure and positioning remain intact
- Color Fidelity: Verifies color accuracy and grayscale conversion
- DPI Handling: Tests resolution scaling and DPI-specific processing
Reporting:
- Detailed filter-by-filter processing logs
- Visual diff outputs showing exact processing changes
- Quantitative metrics for each processing step
- Pass/fail determination for regression testing
- Export-friendly formats for CI/CD integration
The following basic image processing algorithms have been implemented in the enhanced_comparison.py module:
Purpose: Analyzes the distribution and density of content within an image to understand layout characteristics.
Metrics Calculated:
- Overall Content Density: Ratio of non-white pixels to total pixels
- Text Density: Estimated density of text-like structures using morphological operations
- Image Content Density: Density of larger image elements
- White Space Ratio: Proportion of white/empty space
- Density Variance: Measure of how uniformly content is distributed
- Density Entropy: Information-theoretic measure of density distribution
- Dense Clusters: Number of highly dense content regions
Use Cases: Document layout analysis, print quality assessment, content distribution evaluation, scan quality verification
Output: Density heatmap visualization (density_heatmap.png) and quantitative metrics
Purpose: Detects if an image is rotated and estimates the rotation angle using multiple methods.
Methods Used:
- Hough Line Transform: Detects straight lines and calculates their angles
- Text Line Detection: Specifically looks for horizontal text lines
- Principal Component Analysis (PCA): Finds the main direction of edge features
Metrics Calculated:
- Rotation Angle: Estimated rotation in degrees (-45° to +45°)
- Rotation Confidence: Reliability of the rotation detection
- Is Rotated: Boolean indicating if significant rotation is detected
- Method-specific Angles: Results from each detection method
Use Cases: Document orientation correction, scan quality assessment, automated document processing, quality control for printing/scanning
Output: Rotation detection visualization (rotation_detection.png) and angle measurements
Purpose: Analyzes various types of noise present in the image to assess quality.
Noise Types Detected:
- Gaussian Noise: General background noise using Laplacian variance
- Salt and Pepper Noise: Isolated bright/dark pixels
- General Noise Level: Difference from median-filtered version
Metrics Calculated:
- Noise Variance: Laplacian-based noise estimation
- Noise Level: Average noise magnitude
- Salt/Pepper Counts: Number of isolated noise pixels
- Signal-to-Noise Ratio (SNR): Quality metric in dB
- Noise Entropy: Distribution characteristics of noise
- Noise Quality: Categorical assessment (low/medium/high)
Use Cases: Image quality assessment, scanner performance evaluation, print quality analysis, preprocessing requirements determination
Output: Noise visualization (noise_analysis.png) and comprehensive noise metrics
Purpose: Analyzes texture characteristics to understand surface properties and detail preservation.
Methods Used:
- Local Binary Patterns (LBP): Texture descriptor for local patterns
- Contrast Measures: Local standard deviation analysis
- Gradient Analysis: Edge magnitude and direction
- Roughness Calculation: Overall texture variation
Metrics Calculated:
- LBP Uniformity: Consistency of local binary patterns
- Contrast Measure: Average local contrast
- Texture Energy: Overall edge/gradient magnitude
- Direction Uniformity: Consistency of texture orientation
- Roughness: Surface variation measure
- Texture Complexity: Categorical assessment
Use Cases: Material surface analysis, print texture quality, detail preservation assessment, surface defect detection
Output: LBP texture visualization (texture_lbp.png) and contrast visualization (texture_contrast.png)
Purpose: Analyzes geometric properties and distortions in the image.
Analyses Performed:
- Shape Detection: Identifies rectangular and circular objects
- Symmetry Analysis: Horizontal and vertical symmetry
- Line Straightness: Quality of linear elements
- Aspect Ratio: Overall image proportions
Metrics Calculated:
- Aspect Ratio: Width to height ratio
- Average Rectangularity: How well rectangular objects preserve their shape
- Horizontal/Vertical Symmetry: SSIM-based symmetry scores
- Line Straightness: Quality of linear elements
- Geometric Quality: Overall geometric preservation score
Use Cases: Geometric distortion detection, shape preservation assessment, perspective correction evaluation, printing alignment verification
Purpose: Detects whether images are color or monochrome (grayscale) and can distinguish RGB-encoded grayscale from RGB-encoded color images.
Detection Methods:
- Channel Variance Analysis: Examines differences between RGB channels
- Saturation Analysis: Analyzes HSV saturation values
- Correlation Analysis: Measures correlation between RGB channels
- Lab Color Space Analysis: Examines color variance in perceptually uniform space
- Identical Channel Counting: Counts pixels where R=G=B
Metrics Calculated:
- Image Type Classification: Color vs Grayscale for each image
- Detection Confidence: Reliability of the classification
- Channel Differences: Maximum and mean differences between RGB channels
- Saturation Statistics: Mean and maximum saturation values
- Color Pixel Ratio: Proportion of pixels with significant color content
- Channel Correlation: Correlation coefficients between RGB channels
- Color Preservation Score: Whether color type is maintained between original and processed
Use Cases: Color fidelity assessment, grayscale conversion detection, color space analysis, print color mode verification
Output: Detailed classification and confidence metrics for both images
The new algorithms are integrated into the overall quality assessment with weighted contributions:
quality_score = (
ssim * 0.15 + # Basic similarity
edge_quality * 0.12 + # Edge preservation
histogram_similarity * 0.08 + # Color preservation
content_density * 0.05 + # Layout preservation
rotation_score * 0.05 + # Orientation correctness
noise_score * 0.05 + # Noise absence
texture_score * 0.05 + # Texture preservation
geometric_score * 0.05 + # Shape preservation
color_preservation_score * 0.04 + # Color type preservation
# ... other factors
)from enhanced_comparison import ImageComparator
# Initialize comparator
comparator = ImageComparator('original.png', 'processed.png')
# Run individual algorithms
density_results = comparator.image_density_detection()
rotation_results = comparator.rotation_detection()
noise_results = comparator.noise_analysis()
texture_results = comparator.texture_analysis()
geometric_results = comparator.geometric_analysis()
color_results = comparator.color_monochrome_detection()
# Or run all algorithms together
all_results = comparator.run_all_comparisons()Each algorithm generates visualization files to help understand the analysis:
density_heatmap.png: Color-coded density distributionrotation_detection.png: Detected lines used for rotation analysisnoise_analysis.png: Noise distribution visualizationtexture_lbp.png: Local Binary Pattern texture maptexture_contrast.png: Contrast variation map
This project builds on work from the GNOME openQA project and uses free software components including OpenCV, diffoscope, PyMuPDF, and others for image comparison and analysis.