Giter VIP home page Giter VIP logo

anime4ksharp's Introduction

Anime4KSharp

A C# implementation of Anime4K that execute compelete on CPU for getting a better understanding of the algorithm. It works more like a filter than a upscaler in my opinion.

Usage

dotnet Anime4KSharp.dll [input_path] [output_path] [(Optional)scale] [(Optional)push_strength] [(Optional)push_gradient_strength]

default optional parameters:

scale = 2f;
pushGradStrength = scale / 2f;
pushStrength = scale / 6f;

Write-up

Actually this algorithm is as dead simple as bloc97 described in this pseudo-preprint.

Basically this can be described in 5 steps.

Assuming we have the following image:

Original image

Step 1 uses bicubic interpolation to upscale image.

Upscaled image

Step 2 calculates luminances for all pixel and store them in the unused alpha channel.

Luminance map in the alpha channel

Step 3 pushes color based on luminance. Well after doing this we will get an image that looks nearly the same? No, there are differences. Look carefully at the edge of different color and lines, you will notice that they are lighter than the original bicubic upscaled one, especially the lines.

Pushed Color

Step 4 detects edges of the luminance map with Sobel filter. Still, we store them in the alpha channel. However, you will have to invert it before you store it in the alpha channel.

Gradient map Inverted gradient map in the alpha channel

Step 5 is nearly the same as step 3. Instead of getting the lightest color, we use the average color here (doing this can remove some unwanted noise caused by bicubic). And yes, you will want to fill each pixel's alpha with 255 to dump the alpha channel (which contains our gradient map) since we don't want viewer to have a weird image with all the edges seem to be transparent. And here's our final result.

Final result

FYI, here is a zoomed-in comparison between bicubic interpolation and 2 pass Anime4K.

Comparison

TODO

  • Apply FXAA filter to lines in order to get sharper (and smoother) edges.

Acknowledgements

This repository contains images by Rand0mZ and are authorized to used. THEY ARE FOR DEMOSTRATION ONLY, PLEASE DO NOT USE WITHOUT PERMISSION!

This repository is created only for learning purpose. I DO NOT take any responsibilities for any possible damages.

2019, net2cn, in assistance with Rand0mZ.

anime4ksharp's People

Contributors

jdluzen avatar net2cn avatar rand0mzharp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.