portrait_validator_and_enhancer

A powerful Flutter package for automated portrait validation, professional image enhancement, and smart recentering using Google ML Kit.

Features

1. Advanced Quality Gating

  • Blur Detection: Uses Laplacian variance to detect blurry faces before processing.
  • Face Detection & Analysis: Ensures exactly one face is present with ideal pose (yaw, pitch, roll).
  • Occlusion Detection: Detects if the face is covered by masks, hands, or other objects (hijab-friendly).

2. Professional Enhancement

  • Perceptual scaling: Adaptive luminance and color scaling based on image statistics.
  • Skin Tone Protection: Enhances background and clothing without over-saturating or distorting facial skin tones.
  • Adaptive Brightness: Automatically adjusts brightness based on real-time histogram analysis.

3. Smart Recentering & Cropping

  • Orientation Baking: Corrects EXIF rotation issues automatically to prevent "rotated" processing.
  • Dynamic Framing: Smart vertical cropping that considers both hair height and shoulder inclusion for a professional portrait look.
  • White-space Padding: Automatically adds padding if the subject is too close to the edge of the original photo.

4. Background Removal

  • Selfie Segmentation: High-accuracy person segmentation.
  • Bilateral Refinement: Sophisticated edge smoothing for hair and clothing boundaries.
  • Alpha Blending: Smooth transitions between the subject and the new background.

Installation

Add this to your pubspec.yaml:

dependencies:
  portrait_validator_and_enhancer: ^1.0.0

Usage

1. Quality Validation

import 'dart:io';
import 'package:portrait_validator_and_enhancer/portrait_validator_and_enhancer.dart';

final qualityGate = ImageQualityGateService();

// Validate the image for blur, pose, and occlusion
final validationResult = await qualityGate.validate(imageFile);

if (validationResult.isAccepted) {
  print('Photo is high quality!');
} else {
  print('Rejected: ${validationResult.rejectionReason}');
}

2. Smart Recentering & Cropping

final recenterService = FaceRecenterService();

// Automatically center the face and crop to a professional portrait ratio (1200x1200px)
final File croppedFile = await recenterService.recenterFace(imageFile);

3. Adaptive Image Enhancement

final enhancer = ImageEnhancementService();

// Apply noise reduction, histogram equalization, and skin-tone-aware brightness boost
final File enhancedFile = await enhancer.enhanceImage(croppedFile);

4. Background Removal

final bgRemoval = BackgroundRemovalService();

// Remove background with bilateral edge refinement
final File finalFile = await bgRemoval.removeBackground(enhancedFile);

Performance Note

This package uses google_mlkit_face_detection and google_mlkit_selfie_segmentation. Processing high-resolution images may take a few seconds depending on the device hardware.

License

MIT