mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Add AI-powered photo colorization that converts B&W/grayscale images to full color using DDColor (ICCV 2023 dual-decoder architecture) via ONNX Runtime. Includes model selection (Auto/DDColor/Classic), adjustable color intensity, batch processing, before/after preview, and full HEIC/HEIF support. Co-authored-by: stirling-image <stirling-image@users.noreply.github.com>
This commit is contained in:
co-authored by
stirling-image
parent
58cdbe50b4
commit
c280076098
@@ -0,0 +1,46 @@
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { type ProgressCallback, runPythonWithProgress } from "./bridge.js";
|
||||
|
||||
export interface ColorizeOptions {
|
||||
intensity?: number;
|
||||
model?: string;
|
||||
}
|
||||
|
||||
export interface ColorizeResult {
|
||||
buffer: Buffer;
|
||||
width: number;
|
||||
height: number;
|
||||
method: string;
|
||||
}
|
||||
|
||||
export async function colorize(
|
||||
inputBuffer: Buffer,
|
||||
outputDir: string,
|
||||
options: ColorizeOptions = {},
|
||||
onProgress?: ProgressCallback,
|
||||
): Promise<ColorizeResult> {
|
||||
const inputPath = join(outputDir, "input_colorize.png");
|
||||
const outputPath = join(outputDir, "output_colorize.png");
|
||||
|
||||
await writeFile(inputPath, inputBuffer);
|
||||
const { stdout } = await runPythonWithProgress(
|
||||
"colorize.py",
|
||||
[inputPath, outputPath, JSON.stringify(options)],
|
||||
{ onProgress },
|
||||
);
|
||||
|
||||
const result = JSON.parse(stdout);
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || "Colorization failed");
|
||||
}
|
||||
|
||||
const actualOutputPath = result.output_path || outputPath;
|
||||
const buffer = await readFile(actualOutputPath);
|
||||
return {
|
||||
buffer,
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
method: result.method ?? "unknown",
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export { removeBackground } from "./background-removal.js";
|
||||
export { isGpuAvailable, shutdownDispatcher } from "./bridge.js";
|
||||
export { colorize } from "./colorization.js";
|
||||
export type { DetectFacesResult, FaceRegion } from "./face-detection.js";
|
||||
export { blurFaces, detectFaces } from "./face-detection.js";
|
||||
export { inpaint } from "./inpainting.js";
|
||||
|
||||
Reference in New Issue
Block a user