ComfyUI Extension
comfyui_ds
A custom ComfyUI node that implements advanced document scanning with automatic perspective correction and multiple enhancement options.
harishcmgit/comfyui_ds
Nodes3
On cloudLocal install
Categoryimage/processing
Stars0
Updated6 months ago
Nodes (3)
Readme
ComfyUI Document Scanner
A custom ComfyUI node that implements advanced document scanning with automatic perspective correction and multiple enhancement options.
Features
- Automatic Document Detection: Uses contour detection to identify document boundaries
- Perspective Correction: Corrects skewed documents to flat, rectangular format
- Multiple Enhancement Methods: 6 different enhancement algorithms for optimal results
- Batch Processing: Handles multiple images at once
- Debug Visualization: Optional edge detection visualization
- Fallback Safety: Graceful handling of edge cases and errors
Nodes
Document Scanner
Full-featured node with all configuration options:
Inputs:
image: Input document image(s)enhancement_method: Choose from 6 enhancement methodssharpening: General purpose sharpening with HSV adjustmentscartooning: Cartoon-like effect with edge detectionclahe: Contrast Limited Adaptive Histogram Equalizationthreshold: Binary thresholding with Otsu's methodadaptive_threshold: Local adaptive thresholdingflat_field: Flat field correction for uneven lighting
edge_threshold_low/high: Canny edge detection thresholds (20, 70 default)blur_kernel_size: Bilateral filter kernel size (5 default)skip_preprocessing: Skip GrabCut text removal stepreturn_debug_edges: Output edge detection visualization
Outputs:
scanned_image: Final processed documentdebug_edges: Edge detection visualization (if enabled)
Simple Document Scanner
Simplified interface with preset configurations:
Inputs:
image: Input document image(s)enhancement: Choose enhancement presetauto: General purpose (sharpening)text: Optimized for text documents (adaptive threshold)photo: Optimized for photo documents (CLAHE)
Outputs:
scanned_image: Final processed document
Algorithm Overview
- Preprocessing: Optional GrabCut segmentation to remove text
- Grayscale Conversion: Convert to single channel for processing
- Blur: Bilateral filtering for edge-preserving noise reduction
- Edge Detection: Canny edge detection to find document boundaries
- Contour Detection: Find largest quadrilateral contour
- Perspective Correction: Warp document to rectangular format
- Enhancement: Apply selected enhancement method
Installation
- Copy the
comfyui_document_scannerfolder to your ComfyUIcustom_nodesdirectory - Install dependencies:
pip install -r requirements.txt - Restart ComfyUI
- The nodes will appear under
image/processingcategory
Requirements
- opencv-python >= 4.5.0
- numpy >= 1.20.0
- torch >= 1.9.0 (provided by ComfyUI)
Error Handling
The node includes robust error handling:
- If document detection fails, returns original image
- If perspective correction fails, skips correction step
- Graceful fallbacks for all processing steps
- Error messages logged to console
Tips for Best Results
- Use well-lit images with clear document boundaries
- Ensure document occupies significant portion of image
- For text documents, try
adaptive_thresholdenhancement - For photos/mixed content, try
claheorsharpening - Adjust edge detection thresholds if having detection issues
- Use debug edges output to troubleshoot detection problems