kirz_blurry_image_detector 2.0.0
kirz_blurry_image_detector: ^2.0.0 copied to clipboard
Blurry image detector plugin
kirz_blurry_image_detector #
One-pass iOS photo library analyzer for cleaner apps: finds blurry photos and computes perceptual hashes for duplicate detection in a single native sweep with a shared persistent cache.
How it works #
The native side (Swift + Metal) walks the photo library once. For every image it fetches a small 128×128 pixel buffer and computes:
- Sharpness score — variance of the Laplacian (LoG) on gamma luma, evaluated on a 3×3 tile grid and scored by the sharpest tile, so bokeh portraits, night shots and minimalist compositions aren't falsely flagged. GPU-accelerated via MetalPerformanceShaders, batched in one command buffer per 64 images.
- 64-bit dHash — perceptual hash robust to re-compression, resizing and format conversion; two copies of the same photo differ by only a few bits.
Both values are cached persistently per asset id. Re-scans only analyze new photos; the cache survives app restarts, is saved incrementally during the scan (a killed scan resumes where it left off), and prunes deleted assets. Degraded thumbnails (e.g. iCloud-offloaded originals with only a low-res preview available) are never scored — they're retried on a later scan instead of producing false verdicts.
Usage #
import 'package:kirz_blurry_image_detector/kirz_blurry_image_detector.dart';
// Blurry photo ids. Score < threshold == blurry; scores are cached, so
// changing the threshold does NOT trigger a re-scan.
final blurryIds = await BlurryImageDetector.findBlurryImages(
threshold: 0.02, // default
onProgress: (processed, total) => print('$processed / $total'),
);
// Perceptual hashes for duplicate grouping (same scan & cache — if
// findBlurryImages already ran, this returns instantly).
final hashes = await BlurryImageDetector.getImageHashes();
// => { assetLocalIdentifier: 64-bit dHash as int }
Group duplicates by Hamming distance on the returned hashes (e.g. union-find with a distance threshold of ~4 bits for strict duplicates).
Requirements #
- iOS 11+ (MetalPerformanceShaders), photo library permission granted.
- Asset ids are
PHAsset.localIdentifier— the same ids used byphoto_manager'sAssetEntity.id.
Notes #
- iOS only. Android is not supported.
findBlurryImagesandgetImageHashesserialize internally: calling both concurrently performs a single scan.