opencomic-ai-bin
v1.2.1
Published
Upscale and dehalftone images using AI models like Real-CUGAN, Real-ESRGAN, Waifu2x and Upscayl.
Maintainers
Readme
opencomic-ai-bin
This package provides pre-built binaries (realcugan, waifu2x, and upscayl) through a simple Node.js API.
Model files are not included, they are downloaded automatically when needed.
If you prefer to install all models upfront, use the opencomic-ai-models package.
Installation
npm install opencomic-ai-binMethods
This package can be used using CommonJS or ES Module.
// CommonJS
const OpenComicAI = require('opencomic-ai-bin');
// ES Module
import OpenComicAI from 'opencomic-ai-bin';Simple example of package usage
import OpenComicAI from 'opencomic-ai-bin';
import sharp from 'sharp'; // This is optional, only needed if you want to keep ICC profile
(async () => {
// Set the base directory for binary paths, for example change to app.asar.unpacked path in Electron apps
OpenComicAI.setDirname(OpenComicAI.__dirname.replace(/app(-(?:arm64|x64))?\.asar/, 'app$1.asar.unpacked'));
// Models path, if the model is not found in this folder, it will be downloaded
OpenComicAI.setModelsPath('./models');
// Keep ICC profile from input image, requires sharp instance
OpenComicAI.keepIccProfile(sharp);
await OpenComicAI.pipeline('./input.jpg', './output.jpg', [
{
model: '1x_halftone_patch_060000_G',
},
{
model: 'realcugan',
scale: 4,
noise: 0,
}
], (progress) => {
console.log(`Processing: ${Math.round(progress * 100)}%`);
}, {
start: () => {
console.log(`Start download`);
},
progress: (progress) => {
console.log(`Downloading: ${Math.round(progress * 100)}%`);
},
end: () => {
console.log(`End download`);
},
});
})();OpenComicAI.setDirname
Set the base directory for binary paths.
OpenComicAI.setDirname(dirname: string): voidOpenComicAI.setModelsPath
Set the directory where models will be downloaded and stored.
OpenComicAI.setModelsPath(path: string): voidOpenComicAI.setConcurrentDaemons
Set the maximum number of concurrent daemons (upscayl models only), 0 disables daemons.
Daemons help speed up processing loading model only once and not for each image. See comparative performance.
OpenComicAI.setConcurrentDaemons(count: number = 3): voidOpenComicAI.setDaemonIdleTimeout
Set the idle timeout for daemons in milliseconds (upscayl models only).
OpenComicAI.setDaemonIdleTimeout(timeout: number = 60000): voidOpenComicAI.closeAllDaemons
Close all running daemons (upscayl models only).
OpenComicAI.closeAllDaemons(): voidOpenComicAI.keepIccProfile
Keep the ICC profile from the input image, requires a sharp instance to copy the profile from source to dest.
OpenComicAI.keepIccProfile(sharp: any, pipelineColourspace: string = 'rgb16'): voidOpenComicAI.__dirname
Get the base directory for binary paths.
OpenComicAI.__dirname: stringOpenComicAI.models
Object containing all available models organized by type (upscale, descreen, artifact-removal).
OpenComicAI.models: Record<ModelType, Record<string, ModelObject>>OpenComicAI.modelsList
Array of all available model keys.
OpenComicAI.modelsList: Model[]OpenComicAI.modelsTypeList
Models organized by type.
OpenComicAI.modelsTypeList: Record<ModelType, Model[]>OpenComicAI.modelsPath
Current path where models are stored.
OpenComicAI.modelsPath: string | undefinedOpenComicAI.binary
Get the path to the binary executable for a model.
OpenComicAI.binary(model: Model): stringOpenComicAI.model
Get detailed information about a specific model.
OpenComicAI.model(model: Model): ModelObjectOpenComicAI.preload
Preload the model to daemon (upscayl models only) or download the model if not available locally.
OpenComicAI.preload(steps: OpenComicAIOptions[], downloading?: Downloading): Promise<void>OpenComicAI.pipeline
Process an image through one or more AI models.
OpenComicAI.pipeline(
source: string,
dest: string,
steps: OpenComicAIOptions[],
progress?: (progress: number) => void,
downloading?: Downloading
): Promise<string>OpenComicAI.closest
Returns the value in the array closest to the target value.
OpenComicAI.closest(array: number[], target: number): numberTypes
Model
type Model =
| 'realcugan'
| 'realesr-animevideov3'
| 'realesrgan-x4plus'
...ModelType
type ModelType = 'upscale' | 'descreen' | 'artifact-removal';Upscaler
type Upscaler = 'realcugan' | 'upscayl' | 'waifu2x';Speed
type Speed = 'Very Fast' | 'Fast' | 'Medium' | 'Slow' | 'Very Slow';OpenComicAIOptions
interface OpenComicAIOptions {
model?: Model;
noise?: 0 | 1 | 2 | 3;
scale?: number;
tileSize?: number;
gpuId?: string;
threads?: number;
tta?: boolean;
}ModelObject
interface ModelObject {
key?: Model;
name: string;
upscaler: Upscaler;
type?: ModelType;
scales: number[];
noise: number[] | undefined;
latency: number; // From 0.5 (Fatest model) to 10 (Slowest model)
speed?: Speed;
folder: string;
path?: string;
files: string[];
supportCurrentPlatform?: boolean;
}Downloading
interface Downloading {
start?: () => void;
progress?: (progress: number) => void;
end?: () => void;
}Models Info
Artifact removal
Model | Name | Upscaler | Source
------|------|----------|-------
opencomic-ai-artifact-removal-compact | OpenComic AI Artifact Removal Compact | upscayl | ollm/opencomic-ai-training
opencomic-ai-artifact-removal-lite | OpenComic AI Artifact Removal Lite | upscayl | ollm/opencomic-ai-training
opencomic-ai-artifact-removal | OpenComic AI Artifact Removal | upscayl | ollm/opencomic-ai-training
1x_NMKD-Jaywreck3-Lite_320k | NMKD Jaywreck3 Lite | upscayl | NMKD.de
1x_NMKD-Jaywreck3-Soft-Lite_320k | NMKD Jaywreck3 Soft Lite | upscayl | NMKD.de
1x-SaiyaJin-DeJpeg | SaiyaJin DeJpeg | upscayl | OpenModelDB
1x_JPEGDestroyerV2_96000G | JPEG Destroyer V2 | upscayl | Hugging Face
Descreen
Model | Name | Upscaler | Source
------|------|----------|-------
opencomic-ai-descreen-hard-compact | OpenComic AI Descreen Hard Compact | upscayl | ollm/opencomic-ai-training
opencomic-ai-descreen-hard-lite | OpenComic AI Descreen Hard Lite | upscayl | ollm/opencomic-ai-training
1x_halftone_patch_060000_G | Halftone Patch 060000 G | upscayl | NMKD.de
1x_wtp_descreenton_compact | WTP DescreenTon Compact | upscayl | OpenModelDB
Upscale
Model | Name | Upscaler | Source
------|------|----------|-------
realcugan | RealCUGAN | realcugan | Moebytes/waifu2x
realesr-animevideov3 | RealESR AnimeVideo v3 | upscayl | xinntao/Real-ESRGAN
realesrgan-x4plus | RealESRGAN x4 Plus | upscayl | xinntao/Real-ESRGAN
realesrgan-x4plus-anime | RealESRGAN x4 Plus Anime | upscayl | xinntao/Real-ESRGAN
realesrnet-x4plus | RealESRNet x4 Plus | upscayl | xinntao/Real-ESRGAN
waifu2x-models-cunet | Waifu2x CUnet | waifu2x | Moebytes/waifu2x
waifu2x-models-upconv | Waifu2x UpConv | waifu2x | Moebytes/waifu2x
4x-WTP-ColorDS | WTP ColorDS | upscayl | OpenModelDB
remacri-4x | Remacri | upscayl | upscayl/upscayl
ultramix-balanced-4x | Ultramix Balanced | upscayl | upscayl/upscayl
ultrasharp-4x | Ultrasharp | upscayl | upscayl/upscayl
4xInt-RemAnime | Int-RemAnime | upscayl | Phhofm/models
AI-Forever_x4plus | AI-Forever x4plus | upscayl | Hugging Face
4xNomosWebPhoto_esrgan | Nomos Web Photo ESRGAN | upscayl | OpenModelDB
4xHFA2k | HFA2k | upscayl | upscayl/custom-models
4xLSDIRCompactC3 | LSDIR Compact C3 | upscayl | upscayl/custom-models
4xLSDIRplusC | LSDIR Plus C | upscayl | upscayl/custom-models
4x_NMKD-Siax_200k | NMKD Siax | upscayl | upscayl/custom-models
4xNomos8kSC | Nomos 8k SC | upscayl | upscayl/custom-models
RealESRGAN_General_WDN_x4_v3 | RealESRGAN General WDN v3 | upscayl | upscayl/custom-models
RealESRGAN_General_x4_v3 | RealESRGAN General v3 | upscayl | upscayl/custom-models
uniscale_restore_x4 | Uniscale Restore x4 | upscayl | upscayl/custom-models
unknown-2.0.1 | Unknown 2.0.1 | upscayl | upscayl/custom-models
Daemon comparative performance
Table (10 images 512x512px)
Model | Disabled | Enabled | Disabled vs Enabled -------------------------------|-----------------------|----------------------|-------- OpenComic AI Upscale Lite | 52.087s | 7.646s | 6.81x RealESRGAN x4 Plus | 73.273s | 23.199s | 3.16x
OpenComic AI Upscale Lite
Disabled
Processing image 1/10 for model: OpenComic AI Upscale Lite: 2.931s
Processing image 2/10 for model: OpenComic AI Upscale Lite: 4.464s
Processing image 3/10 for model: OpenComic AI Upscale Lite: 5.594s
Processing image 4/10 for model: OpenComic AI Upscale Lite: 5.561s
Processing image 5/10 for model: OpenComic AI Upscale Lite: 5.521s
Processing image 6/10 for model: OpenComic AI Upscale Lite: 5.531s
Processing image 7/10 for model: OpenComic AI Upscale Lite: 5.534s
Processing image 8/10 for model: OpenComic AI Upscale Lite: 5.555s
Processing image 9/10 for model: OpenComic AI Upscale Lite: 5.496s
Processing image 10/10 for model: OpenComic AI Upscale Lite: 5.898s
Model: OpenComic AI Upscale Lite, Latency: 52.087sEnabled
Preloading model... OpenComic AI Upscale Lite
Preload model: OpenComic AI Upscale Lite: 473.897ms
Processing image 1/10 for model: OpenComic AI Upscale Lite: 725.474ms
Processing image 2/10 for model: OpenComic AI Upscale Lite: 716.566ms
Processing image 3/10 for model: OpenComic AI Upscale Lite: 716.221ms
Processing image 4/10 for model: OpenComic AI Upscale Lite: 715.214ms
Processing image 5/10 for model: OpenComic AI Upscale Lite: 717.894ms
Processing image 6/10 for model: OpenComic AI Upscale Lite: 715.236ms
Processing image 7/10 for model: OpenComic AI Upscale Lite: 716.296ms
Processing image 8/10 for model: OpenComic AI Upscale Lite: 714.025ms
Processing image 9/10 for model: OpenComic AI Upscale Lite: 718.653ms
Processing image 10/10 for model: OpenComic AI Upscale Lite: 714.792ms
Model: OpenComic AI Upscale Lite, Latency: 7.646sRealESRGAN x4 Plus
Disabled
Processing image 1/10 for model: RealESRGAN x4 Plus: 6.473s
Processing image 2/10 for model: RealESRGAN x4 Plus: 7.809s
Processing image 3/10 for model: RealESRGAN x4 Plus: 7.690s
Processing image 4/10 for model: RealESRGAN x4 Plus: 7.470s
Processing image 5/10 for model: RealESRGAN x4 Plus: 6.620s
Processing image 6/10 for model: RealESRGAN x4 Plus: 7.390s
Processing image 7/10 for model: RealESRGAN x4 Plus: 7.423s
Processing image 8/10 for model: RealESRGAN x4 Plus: 7.541s
Processing image 9/10 for model: RealESRGAN x4 Plus: 7.536s
Processing image 10/10 for model: RealESRGAN x4 Plus: 7.321s
Model: RealESRGAN x4 Plus, Latency: 73.273sEnabled
Preloading model... RealESRGAN x4 Plus
Preload model: RealESRGAN x4 Plus: 1.165s
Processing image 1/10 for model: RealESRGAN x4 Plus: 2.217s
Processing image 2/10 for model: RealESRGAN x4 Plus: 2.196s
Processing image 3/10 for model: RealESRGAN x4 Plus: 2.203s
Processing image 4/10 for model: RealESRGAN x4 Plus: 2.191s
Processing image 5/10 for model: RealESRGAN x4 Plus: 2.200s
Processing image 6/10 for model: RealESRGAN x4 Plus: 2.203s
Processing image 7/10 for model: RealESRGAN x4 Plus: 2.216s
Processing image 8/10 for model: RealESRGAN x4 Plus: 2.222s
Processing image 9/10 for model: RealESRGAN x4 Plus: 2.188s
Processing image 10/10 for model: RealESRGAN x4 Plus: 2.194s
Model: RealESRGAN x4 Plus, Latency: 23.199sCredits
This project uses the following AI models and upscalers:
