Posted on Leave a comment

Even better image upscaling with Waifu2x

You may have already seen the article here in the Magazine about upscaling bitmap images with better quality. That article covered a few utilities to achieve good results, but there’s always room for enhancement. Meet Waifu2x, a sophisticated tool that uses deep convolutional neural networks, or machine learning for short. Therefore it benefits from trained model data sets. Read on to see how well it performs to upscale your images, and how to get the same benefits even without an Nvidia card.

Here are some examples. First, a character that will be familiar to Fedora fans:

Making the Beefy Miracle hot dog four times larger keeps it nearly perfect!

Here’s another example:

Upscaling a drawing from an old book delivers really outstanding results.

Because Waifu2x performs the calculations using Nvidia CUDA computing platform, it requires an Nvidia graphics card. This article, however, covers a more portable version called Waifu2x-converter-cpp that runs everywhere.

Waifu2x-converter-cpp doesn’t require a dedicated Nvidia GPU. Instead, it leverages the OpenCV and OpenCL libraries. Although the overall performance is slower compared to the original code, it’s portable and more people are able to use it. And of course it runs on Fedora!

Follow the directions below to give it a spin.

Installing Waifu2x-converter-cpp in Fedora

To build the application from source, first install build dependencies:

sudo dnf install -y gcc-c++ cmake opencv-devel opencl-utils-devel

Then grab the source code, build it and install the files:

git clone https://github.com/DeadSix27/waifu2x-converter-cpp.git cd waifu2x-converter-cpp/build cmake -DLIB_SUFFIX=64 ../ make sudo make install

Tell the dynamic library linker to index the directory with locally installed libraries:

sudo ldconfig /usr/local/lib64

Now everything is ready for upscaling. The example command for processing an image is as follows:

waifu2x-converter-cpp --scale_ratio 2 -i /path/to/input_file -o /path/to/output_file

Don’t miss this very helpful command for extras, such as switching OpenCL on/off, playing with noise level, and so on:

waifu2x-converter-cpp --help

Using a graphical front-end for Waifu2x

Another step forward is to install Qtwaifu2x, a graphical tool that lets you escape Fedora terminal and process images with comfort and convenience.

Practically all you have to do is hit Browse and Start to launch the upscaling task.

Installing Qtwaifu2x in Fedora

First, install the main build dependency:

sudo dnf install -y qt5-qtbase-devel

Then get the code and build it:

git clone https://github.com/cmdrkotori/qtwaifu2x.git cd qtwaifu2x qmake-qt5 && make

To run the application from the current directory:

./qtwaifu2x

The main window has quite a few options, but it’s usually enough to provide the input file and hit the Start button.

Brew yourself a cup of tea and come back in a while to enjoy the perfectly upscaled image!

Posted on Leave a comment

Upscale bitmap images with better results

Most images on the Web are small or medium sized, since otherwise users need to wait longer before their favorite web pages load. However, sometimes you need to find a larger version of an image, but the search doesn’t bear fruit. Any bitmap image can be scaled up or down in an image editor (such as Gimp). But obviously upscaling would not add any detail to the image. Instead, the result will usually be blurred, pixelated and noticeably stretched-up. In this brief roundup we’ll try to upscale bitmap images with a little better result.

There’s no magic in it, just a few advanced scaling algorithms that help produce better-looking pictures. Everything is open source and works great in Fedora. The results will be tested against the Cubic interpolation method, which Gimp applies by default.

Filters in ImageMagick

This is the most famous and widely used open source software for manipulating images from the command line. Fedora, like the majority of other Linux distributions, already includes ImageMagick. Fedora even installs it by default in Fedora Workstation. ImageMagick provides  the convert command, which can also change dimensions of input images.

The trick is that convert supports filters, and ImageMagick provides a rich selection of such filters, some of which work really good for upscaling. You can check out the full list here. For instance, the point filter works well for upscaling pixel art and screen shots, as it preserves clarity and sharpness at the cost of emphasized pixels. Still, this can look better than the blurred results of the convenient Cubic algorithm.

Use it with the following syntax:

convert input.png -filter point -resize 600% output.png

The PNG file format as well as the 600% scaling factor are just examples.

Hiding pixels in Cubic is not really good for upscaling. Use something without anti-aliasing, such as the Point filter in ImageMagick.

Although it’s possible to get the same result in Gimp by choosing the None interpolation method, working with ImageMagick is sometimes easier. Not only it is installed in Fedora Workstation by default (Gimp is available, but not installed), it provides command-line tools which are ideal for scripting.

Xbrzscale

Xbrzscale is a command-line utility that implements the xBR scaling method. In brief, xBR is based on pattern recognition and interpolation, and it’s perfect for magnifying pixel art. xBRZ is an enhanced version of xBR, with a focus on preserving very small details. Therefore, xBRZ delivers pleasing results on both pixel art and photographic images, such as portraits.

In the following side-by-side comparison, the left part definitely looks preferable thanks to the superb clarity.

The Xbrzscale version features sharper edges and looks as if it had more details than the version to the right.

Install Xbrzscale in Fedora

To build this tool from source, you must install some prerequisites first:

sudo dnf -y install gcc-c++ SDL2-devel SDL2_image-devel

Let’s go ahead with Xbrzscale now:

git clone https://github.com/atheros/xbrzscale.git cd xbrzscale make

The command line syntax to upscale with this software is:

./xbrzscale X input.png output.png

…where X is the scale factor, a number within the range of 2 to 6.

Note that Xbrzscale always outputs PNG images, no matter what you feed it with. If the input file format is different, Xbrzscale will convert it to PNG.

Smilla Enlarger

Smilla Enlarger has a user-friendly graphical interface. It makes use of yet another different technology, this time based on fractal-based interpolation algorithms. The main goal is to produce sharper results when you upscale photographic images. The enlarged image usually preserves more details than the Cubic interpolation can.

Install Smilla Enlarger in Fedora

Again, start by installing the build dependencies:

sudo dnf -y install qt5-qtbase-devel

Now, build and run Smilla Enlarger:

git clone https://github.com/lupoDharkael/smilla-enlarger.git cd smilla-enlarger qmake-qt5 && make ./smilla-enlarger

The application window has numerous advanced controls and extra parameters that put a user in control of upscaling details.

Smilla Enlarger lets you choose a zoom factor, configure cropping and, more importantly, preview the result before hitting the Enlarge & Save button.

The upscale version of the sample image looks noticeably different from both the decent Xbrzscale version and the cubic-enlarged version.

Smill Enlarger adds a subtle amount of grain, which seems to effectively hide artifacts and make a picture look cleaner. Try this application on a photo to get the best results.

It’s hard to recommend the plethora of ImageMagick filters over Xbrzscale and Smilla Enlarger. The actual results will vary across different sorts of images, and of course different user preferences.