feat(red-eye-removal): SOTA red eye removal with MediaPipe Face Mesh + OpenCV LAB correction (#60)

Uses MediaPipe Face Mesh (refine_landmarks=True) for precise iris localization
and OpenCV LAB color space for accurate red-eye detection and luminance-preserving
correction. Zero new dependencies - leverages existing MediaPipe + OpenCV stack.

- Sensitivity slider (LAB 'a' channel threshold)
- Correction strength slider (pupil darkening factor)
- Output format selector (Original/PNG/JPEG/WebP)
- Before/after preview, progress stages, batch processing
- Pipeline support via Controls/Settings split

Co-authored-by: stirling-image <stirling-image@users.noreply.github.com>
This commit is contained in:
stirling-image
2026-04-13 20:22:30 +08:00
committed by GitHub
co-authored by stirling-image
parent dfffc0a8cc
commit 9ddeac92b6
9 changed files with 705 additions and 0 deletions
+1
View File
@@ -6,5 +6,6 @@ export { blurFaces, detectFaces } from "./face-detection.js";
export { inpaint } from "./inpainting.js";
export { noiseRemoval } from "./noise-removal.js";
export { extractText } from "./ocr.js";
export { removeRedEye } from "./red-eye-removal.js";
export { seamCarve } from "./seam-carving.js";
export { upscale } from "./upscaling.js";
+52
View File
@@ -0,0 +1,52 @@
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { type ProgressCallback, runPythonWithProgress } from "./bridge.js";
export interface RedEyeRemovalOptions {
sensitivity?: number;
strength?: number;
format?: string;
quality?: number;
}
export interface RedEyeRemovalResult {
buffer: Buffer;
facesDetected: number;
eyesCorrected: number;
width: number;
height: number;
format: string;
}
export async function removeRedEye(
inputBuffer: Buffer,
outputDir: string,
options: RedEyeRemovalOptions = {},
onProgress?: ProgressCallback,
): Promise<RedEyeRemovalResult> {
const inputPath = join(outputDir, "input_redeye.png");
const outputPath = join(outputDir, "output_redeye.png");
await writeFile(inputPath, inputBuffer);
const { stdout } = await runPythonWithProgress(
"red_eye_removal.py",
[inputPath, outputPath, JSON.stringify(options)],
{ onProgress },
);
const result = JSON.parse(stdout);
if (!result.success) {
throw new Error(result.error || "Red eye removal failed");
}
const actualOutputPath = result.output_path || outputPath;
const buffer = await readFile(actualOutputPath);
return {
buffer,
facesDetected: result.facesDetected ?? 0,
eyesCorrected: result.eyesCorrected ?? 0,
width: result.width,
height: result.height,
format: result.format ?? "png",
};
}