A Flutter package for analyzing images including blur detection, quality assessment, and OCR text recognition using Google ML Kit.
- 🔍 Blur Detection: Detects overall and localized blur in images using Laplacian variance and gradient analysis
- ⭐ Quality Assessment: Evaluates image quality based on resolution, sharpness, and compression
- 📖 Readability Assessment: Text-focused quality scoring that predicts OCR success probability
- ✂️ Text Cut-Off Detection: Detects when text appears clipped at the image edges
- 📝 OCR Text Recognition: Extracts text from images using Google ML Kit
- 📊 Detailed Analysis: Provides comprehensive metrics including dimensions, file size, and localized blur scores
Add this to your package's pubspec.yaml file:
dependencies: flutter_image_inspector: ^1.0.0
Then run:
flutter pub get
By default, blur detection, quality assessment, and readability assessment are enabled (OCR is off):
import 'package:flutter_image_inspector/flutter_image_inspector.dart'; import 'package:image_picker/image_picker.dart'; // Using file path (recommended) final picker = ImagePicker(); final image = await picker.pickImage(source: ImageSource.gallery); if (image != null) { final service = ImageAnalysisService(); final result = await service.analyzeImage(imageFilePath: image.path); // Access results print('Quality: ${result.qualityScore}'); // 0.0 = low, 1.0 = high print('Blur: ${result.blurDescription}'); print('Dimensions: ${result.width}x${result.height}'); print('File size: ${result.fileSizeMB} MB'); } // Or using image bytes final Uint8List imageBytes = await image.readAsBytes(); final result = await service.analyzeImage(imageBytes: imageBytes);
Enable only the features you need for better performance:
final service = ImageAnalysisService(); final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig( enableBlurDetection: false, enableQualityAssessment: false, enableReadabilityAssessment: false, enableOCR: true, ), ); print('Text: ${result.extractedText}');
final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig( enableBlurDetection: false, enableQualityAssessment: true, enableReadabilityAssessment: false, enableOCR: false, ), ); print('Quality: ${result.qualityDescription}');
final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig( enableBlurDetection: true, enableQualityAssessment: false, enableReadabilityAssessment: false, enableOCR: false, ), ); if (result.isBlurry) { print('Image is blurry: ${result.blurDescription}'); }
// Readability assessment runs OCR internally to evaluate how reliably // text in the image can be read, and flags text that appears cut off // at the edges. final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig( enableBlurDetection: false, enableQualityAssessment: false, enableReadabilityAssessment: true, enableOCR: false, ), ); print('Readability: ${result.readabilityScore}'); if (result.isCutOff) { print('Text cut off at: ${result.cutOffEdges?.join(", ")}'); }
final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig.all(), );
final service = ImageAnalysisService(); // Analyze with custom config final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig( enableBlurDetection: true, enableQualityAssessment: true, enableReadabilityAssessment: true, enableOCR: true, ), ); // Check blur (if enabled) if (result.isBlurry) { print('Image is blurry: ${result.blurDescription}'); } // Check for localized blur (if blur detection enabled) if (result.hasLocalizedBlur) { print('Localized blur detected!'); print('Most blurry region: ${result.mostBlurryRegion}'); result.localizedBlurScores?.forEach((region, score) { print('$region: ${(score * 100).toStringAsFixed(1)}% blur'); }); } // Check quality (if enabled) print('Quality: ${result.qualityDescription}'); // High, Medium, Low, Very Low // Check readability (if enabled) if (result.readabilityScore != null) { print('Readability: ${(result.readabilityScore! * 100).toStringAsFixed(1)}%'); } // Check text cut-off (if readability enabled) if (result.isCutOff) { print('Text cut off at: ${result.cutOffEdges?.join(", ")}'); } // Check OCR (if enabled) if (result.hasText) { print('Extracted text: ${result.extractedText}'); }
import 'package:flutter/material.dart'; import 'package:flutter_image_inspector/flutter_image_inspector.dart'; import 'package:image_picker/image_picker.dart'; import 'dart:typed_data'; class ImageAnalysisWidget extends StatefulWidget { @override _ImageAnalysisWidgetState createState() => _ImageAnalysisWidgetState(); } class _ImageAnalysisWidgetState extends State<ImageAnalysisWidget> { final ImageAnalysisService _service = ImageAnalysisService(); AnalysisResult? _result; bool _isAnalyzing = false; Future<void> _analyzeImage() async { final picker = ImagePicker(); final image = await picker.pickImage(source: ImageSource.gallery); if (image == null) return; setState(() => _isAnalyzing = true); try { // Use file path for better OCR support final result = await _service.analyzeImage( imageFilePath: image.path, config: AnalysisConfig.all(), // Enable all features ); setState(() { _result = result; _isAnalyzing = false; }); } catch (e) { setState(() => _isAnalyzing = false); print('Error: $e'); } } @override Widget build(BuildContext context) { return Column( children: [ ElevatedButton( onPressed: _isAnalyzing ? null : _analyzeImage, child: Text(_isAnalyzing ? 'Analyzing...' : 'Analyze Image'), ), if (_result != null) ...[ if (_result!.blurScore > 0) // Only show if blur was enabled Text('Blur: ${_result!.blurScore.toStringAsFixed(2)}'), Text('Quality: ${_result!.qualityDescription}'), if (_result!.hasText) Text('Text: ${_result!.extractedText}'), ], ], ); } }
Main service for analyzing images.
Analyzes an image with configurable features and returns analysis results.
Parameters:
imageBytes(Uint8List?, optional): The image data as bytesimageFilePath(String?, optional): Path to image file (better OCR support)config(AnalysisConfig, optional): Feature configuration (default: quality only)
Note: Either imageBytes or imageFilePath must be provided.
Returns:
Future<AnalysisResult>: Analysis result containing enabled metrics
Throws:
ArgumentError: If neither imageBytes nor imageFilePath providedException: If image cannot be decoded or file not found
Example:
// Using file path final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', ); // Using bytes final result = await service.analyzeImage( imageBytes: imageBytes, ); // Custom config final result = await service.analyzeImage( imageFilePath: '/path/to/image.jpg', config: AnalysisConfig(enableOCR: true), );
Configuration class for enabling/disabling analysis features.
AnalysisConfig()- Default: blur detection, quality, and readability enabled (OCR off)AnalysisConfig.all()- All features enabledAnalysisConfig.none()- All features disabled
bool enableBlurDetection- Enable blur detection (default:true)bool enableQualityAssessment- Enable quality assessment (default:true)bool enableReadabilityAssessment- Enable readability assessment and text cut-off detection (default:true). Runs OCR internally even whenenableOCRisfalse.bool enableOCR- Enable OCR text recognition (default:false)
Result object containing analysis metrics (null/default values for disabled features).
bool isBlurry- Whether the image is blurry (default:falseif blur disabled)double blurScore- Blur score 0.0-1.0 (default:0.0if blur disabled)Map<String, double>? localizedBlurScores- Regional blur scores (nullif blur disabled)double qualityScore- Quality score 0.0-1.0 (default:0.0if quality disabled). Incorporates readability when a large amount of text is detected.double? readabilityScore- Readability score 0.0-1.0 (nullif readability disabled or no significant text detected)bool hasText- Whether text was detected (default:falseif OCR disabled)String? extractedText- Extracted text (nullif OCR disabled or no text)bool isCutOff- Whether text appears cut off at the image edges (default:falseif readability disabled)List<String>? cutOffEdges- Edges where text appears cut off:"top","bottom","left","right"(nullif readability disabled or no cut-off detected)int width- Image width in pixels (always available)int height- Image height in pixels (always available)double fileSizeMB- File size in megabytes (always available)
String blurDescription- Blur description (only meaningful if blur enabled)String qualityDescription- Quality description (only meaningful if quality enabled)String? mostBlurryRegion- Most blurry region name (nullif blur disabled)bool hasLocalizedBlur- Whether localized blur detected (falseif blur disabled)
The package uses two methods for blur detection:
- Laplacian Variance: Measures edge strength across the image
- Gradient Magnitude Analysis: Analyzes gradient magnitudes to detect content blur
The algorithm divides the image into a 3x3 grid (9 regions) and calculates blur scores for each region, allowing detection of localized blur spots. The overall blur score combines the whole-image average (50%) with the most blurry region (50%), so a single blurry spot still affects the result.
Quality score is calculated based on:
- Resolution (30% weight): Higher resolution = better quality (sharpness-adjusted, so very sharp low-resolution images aren't over-penalized)
- Sharpness (50% weight): Less blur = better quality
- Compression (20% weight): Bits-per-pixel relative to resolution; penalizes over-compression artifacts
When a large amount of text is detected, the quality score is blended 50/50 with the readability score.
Predicts how reliably text in the image can be read (OCR success probability), weighted toward text needs:
- Sharpness (60% weight): Text requires higher sharpness than general images
- Resolution (20% weight): Adequate resolution for legible text
- Compression (20% weight): Text is especially sensitive to compression artifacts
Readability assessment runs OCR internally (even when enableOCR is false) to determine whether the image contains a significant amount of text.
Enabled together with readability assessment. Scans a narrow band along each of the four image edges for high-contrast, text-like patterns that suggest text continues beyond the boundary, and reports which edges (top, bottom, left, right) appear to clip text.
Uses Google ML Kit Text Recognition to:
- Process the image
- Detect and extract text
- Return extracted text in results
This package targets mobile platforms only. OCR (Google ML Kit) and
file-path input are Android/iOS features, and the core service uses dart:io.
- ✅ Android
- ✅ iOS
- ❌ Web (not supported)
- ❌ Desktop (not supported)
- Flutter SDK >=3.0.0
- Dart SDK >=3.9.0
- Android: minSdk 21+
- iOS: iOS 13.0+
image: ^4.3.0- Image processinggoogle_mlkit_text_recognition: ^0.12.0- OCR functionality
See the example/ directory for a complete example app demonstrating all features.
To run the example:
cd example
flutter pub get
flutter runContributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available for use.
For questions or issues:
- Check existing issues in the repository
- Review the example app for usage examples
- Open a new issue if needed
See CHANGELOG.md for version history.