GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ibnekhan/flutter-image-inspector

BranchesTags
Open more actions menu

Latest commit

 

History

3 Commits
3 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
example
example
 
 
lib
lib
 
 
test
test
 
 
.fvmrc
.fvmrc
 
 
.gitignore
.gitignore
 
 
.metadata
.metadata
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
PACKAGE_CONVERSION_PLAN.md
PACKAGE_CONVERSION_PLAN.md
 
 
README.md
README.md
 
 
analysis_options.yaml
analysis_options.yaml
 
 
pubspec.lock
pubspec.lock
 
 
pubspec.yaml
pubspec.yaml
 
 

Repository files navigation

flutter_image_inspector

A Flutter package for analyzing images including blur detection, quality assessment, and OCR text recognition using Google ML Kit.

Features

  • 🔍 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

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_image_inspector: ^1.0.0

Then run:

flutter pub get

Usage

Basic Usage (Default)

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);

Feature Customization

Enable only the features you need for better performance:

Only OCR

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}');

Only Quality

final result = await service.analyzeImage(
  imageFilePath: '/path/to/image.jpg',
  config: AnalysisConfig(
    enableBlurDetection: false,
    enableQualityAssessment: true,
    enableReadabilityAssessment: false,
    enableOCR: false,
  ),
);
print('Quality: ${result.qualityDescription}');

Only Blur Detection

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 & Cut-Off Detection

// 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(", ")}');
}

All Features

final result = await service.analyzeImage(
  imageFilePath: '/path/to/image.jpg',
  config: AnalysisConfig.all(),
);

Advanced Usage

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}');
}

Complete Example

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}'),
        ],
      ],
    );
  }
}

API Reference

ImageAnalysisService

Main service for analyzing images.

Methods

analyzeImage({Uint8List? imageBytes, String? imageFilePath, AnalysisConfig config})

Analyzes an image with configurable features and returns analysis results.

Parameters:

  • imageBytes (Uint8List?, optional): The image data as bytes
  • imageFilePath (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 provided
  • Exception: 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),
);

AnalysisConfig

Configuration class for enabling/disabling analysis features.

Constructors

  • AnalysisConfig() - Default: blur detection, quality, and readability enabled (OCR off)
  • AnalysisConfig.all() - All features enabled
  • AnalysisConfig.none() - All features disabled

Properties

  • 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 when enableOCR is false.
  • bool enableOCR - Enable OCR text recognition (default: false)

AnalysisResult

Result object containing analysis metrics (null/default values for disabled features).

Properties

  • bool isBlurry - Whether the image is blurry (default: false if blur disabled)
  • double blurScore - Blur score 0.0-1.0 (default: 0.0 if blur disabled)
  • Map<String, double>? localizedBlurScores - Regional blur scores (null if blur disabled)
  • double qualityScore - Quality score 0.0-1.0 (default: 0.0 if quality disabled). Incorporates readability when a large amount of text is detected.
  • double? readabilityScore - Readability score 0.0-1.0 (null if readability disabled or no significant text detected)
  • bool hasText - Whether text was detected (default: false if OCR disabled)
  • String? extractedText - Extracted text (null if OCR disabled or no text)
  • bool isCutOff - Whether text appears cut off at the image edges (default: false if readability disabled)
  • List<String>? cutOffEdges - Edges where text appears cut off: "top", "bottom", "left", "right" (null if 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)

Getters

  • String blurDescription - Blur description (only meaningful if blur enabled)
  • String qualityDescription - Quality description (only meaningful if quality enabled)
  • String? mostBlurryRegion - Most blurry region name (null if blur disabled)
  • bool hasLocalizedBlur - Whether localized blur detected (false if blur disabled)

How It Works

Blur Detection

The package uses two methods for blur detection:

  1. Laplacian Variance: Measures edge strength across the image
  2. 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 Assessment

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.

Readability Assessment

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.

Text Cut-Off Detection

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.

OCR Detection

Uses Google ML Kit Text Recognition to:

  1. Process the image
  2. Detect and extract text
  3. Return extracted text in results

Platform Support

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)

Requirements

  • Flutter SDK >=3.0.0
  • Dart SDK >=3.9.0
  • Android: minSdk 21+
  • iOS: iOS 13.0+

Dependencies

  • image: ^4.3.0 - Image processing
  • google_mlkit_text_recognition: ^0.12.0 - OCR functionality

Example App

See the example/ directory for a complete example app demonstrating all features.

To run the example:

cd example
flutter pub get
flutter run

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available for use.

Support

For questions or issues:

  • Check existing issues in the repository
  • Review the example app for usage examples
  • Open a new issue if needed

Changelog

See CHANGELOG.md for version history.

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.