Sharpy
High-performance image sharpening library and CLI tool for Rust.
Quick Start
Library Usage
use Image;
// Load and sharpen an image
let image = load?;
let sharpened = image.unsharp_mask?;
sharpened.save?;
CLI Usage
# Install the CLI tool
# Sharpen an image
# Use a preset
Features
- 🚀 Fast - Parallel processing with Rayon
- 🎯 Multiple algorithms - Unsharp mask, high-pass, edge enhancement, clarity
- 🔧 Flexible API - Builder pattern for complex workflows
- 📦 Zero dependencies - Only depends on
imageandrayon - 🖥️ CLI included - Full-featured command-line tool
Installation
As a Library
Add to your Cargo.toml:
[]
= "0.1"
As a CLI Tool
Or build from source:
Library Usage
Basic Sharpening
use ;
// Unsharp mask - the classic sharpening method
let image = load?;
let sharpened = image.unsharp_mask?;
// High-pass sharpening
let sharpened = image.high_pass_sharpen?;
// Edge enhancement
let sharpened = image.enhance_edges?;
// Clarity (local contrast enhancement)
let sharpened = image.clarity?;
Using the Builder Pattern
use ;
let result = load?
.sharpen
.unsharp_mask
.edge_enhance
.clarity
.apply?;
result.save?;
Using Presets
use ;
// Built-in presets for common use cases
let image = load?;
// Subtle sharpening
let result = subtle.apply?;
// Portrait enhancement (avoids over-sharpening skin)
let result = portrait.apply?;
// Landscape enhancement (maximum detail)
let result = landscape.apply?;
Advanced Examples
Custom Sharpening Pipeline
use ;
Processing Multiple Images
use Image;
use *;
use Path;
Working with Image Data
use Image;
use ;
// From various image types
let rgb_image = new;
let image = from_rgb;
let dynamic_image = new_rgb8;
let image = from_dynamic;
// Get dimensions and histogram
let = image.dimensions;
let histogram = image.histogram; // [u32; 256] luminance histogram
// Convert back to standard image types
let rgb: RgbImage = image.clone.into_rgb;
let dynamic: DynamicImage = image.into_dynamic;
CLI Tool (sharpy)
Basic Commands
# Unsharp mask with default settings
# Specify parameters
# High-pass sharpening
# Edge enhancement
# Clarity enhancement
# Use a preset
Available Presets
subtle- Light sharpening for general usemoderate- Balanced sharpening with claritystrong- Heavy sharpening for soft imagesedge-aware- Emphasizes edges while preserving smooth areasportrait- Optimized for portraits (avoids over-sharpening skin)landscape- Maximum detail extraction for landscapes
Batch Processing
# Process all JPG files in current directory
# Process with custom suffix
# Apply multiple operations
Advanced CLI Usage
Dry Run Mode
# Preview what would happen without processing
Verbose Output
# See detailed processing information
Overwrite Protection
# Force overwrite existing files
Chaining Operations in Batch Mode
# Format: "operation:param1:param2:..."
Operation formats:
unsharp:radius:amount:thresholdhighpass:strengthedges:strength:method(method: sobel or prewitt)clarity:strength:radius
CLI Examples by Use Case
Portrait Photography
# Gentle sharpening for portraits
# Custom portrait enhancement
Landscape Photography
# Maximum detail for landscapes
# Custom landscape workflow
Web Images
# Batch process for web upload
Scanned Documents
# Enhance text clarity
Performance
Sharpy uses parallel processing for optimal performance:
- Separable convolution for Gaussian blur
- Parallel pixel processing with Rayon
- Efficient memory usage with copy-on-write
- Zero-copy operations where possible
Benchmark results (1024x1024 image):
- Unsharp mask: ~45ms
- High-pass sharpen: ~25ms
- Edge enhancement: ~35ms
- Clarity: ~65ms
Algorithm Details
Unsharp Mask
Creates a blurred version of the image and subtracts it from the original to enhance edges.
Parameters:
radius: Blur radius (0.5-10.0)amount: Strength multiplier (0.0-5.0)threshold: Minimum difference to sharpen (0-255)
High-Pass Sharpen
Uses a 3x3 convolution kernel to enhance high-frequency details.
Parameters:
strength: Blend with original (0.0-3.0)
Edge Enhancement
Detects edges using Sobel or Prewitt operators and enhances them.
Parameters:
strength: Enhancement amount (0.0-3.0)method: Edge detection algorithm (Sobel/Prewitt)
Clarity
Enhances local contrast by comparing each pixel to its surrounding area.
Parameters:
strength: Enhancement amount (0.0-3.0)radius: Local area size (1.0-20.0)
Building from Source
# Clone the repository
# Build library and CLI
# Run tests
# Run benchmarks
# Install CLI globally
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.