ScaleNx

Scale2x, Scale3x, Scale2xSFX and Scale3xSFX image scaling in pure Python

Scale2x and Scale3x algorithms (sometimes referred to as AdvMAME2x and AdvMAME3x) were initially developed by Andrea Mazzoleni for scaling up graphics like game sprites and icons without introducing new colors and blurring contrast edges. That's what it was invented for, and nothing else.

Later on, Scale2xSFX and Scale3xSFX were introduced for the same goal, providing different diagonals rendering and eliminating artifacts initial ScaleNx produce on some patterns.

However, it appears that ScaleNx may be successfully misused for absolutely different task: scaling up low-res text scans before OCR, and drawings before tracing them to vectors.

Proceed to Github

For this purpose I created pure Python implementation of ScaleNx algorithms, which can be downloaded from GitHub. By saying «pure Python» I mean it - it doesn't even use bytearrays, only lists of lists of lists. Consider it a spiritual practice or whatever. You can download it as «ScaleNx» module to import into other software and/or just to laugh at it.

ScaleNx package includes suitable human-ready GUI shell, not surprisingly called ScaleNxGUI.py, providing easy launch of single PNG, PPM or PGM (PBM support is limited to reading only, result may be saved to another format like PNG) file rescaling procedure or batch rescaling of all PNG images in chosen folder and subfolders. Note that batch processing uses asynchronous multiprocessing, greatly reducing run time for a price of devouring next to 100% of CPU power, taking RAM for several images simultaneously, and rendering GUI rather unresponsive, looking like it hung up. Don't worry, it can't hang up, it can only possibly crash when trying to process really huge images (although for most recent version I yet have to see it).

Needless to say, PNG support in ScaleNxGUI is provided with PyPNG, and PPM and PGM support with PyPNM; both are pure Python modules, therefore allow making the whole program quite cross-platform.

Download site

Download content

Github

ScaleNx module and user-friendly application for single file or batch image rescaling.

PyPI

ScaleNx module only.

Update: - Version 25.02.09.18 of main program have no change in ScaleNx module but is relinked with updated version of PyPNM module providing per row file writing, thus reducing memory usage; PyPNG data exchange changed to row generators thus making memory usage as small as possible with this format.On my rather old notebook main ScaleNxGUI program appeared to be able to upscale 8224x8224 px RGB image with Scale2x and Scale2xSFX up to 16448x16448 px, and then successfully save the result as both PNG and PPM. Considering the fact that resulting image will be something like 1.4x1.4 meter printed at 300 ppi, I assume that further experiments with processing larger images on my notebook may raise doubts in may officially confirmed "mentally sane" status.

Update: - In version 25.02.01 FIR optimization of Scale2x, Scale3x, Scale2xSFX and Scale3xSFX performed, speed gain is in range from ca. 15% for Scale2x to ca. 50% for the others (since Scale2x work on minimal kernel already, there's not much room for further list read access reduction, therefore speed increase is minimal).

For Windows users, there is compiled exe binary available for download at newest release page, what as to other platform, since the program is pure Python and quite self-contained, release source is supposed to work with any recent canonic Python installation right out of the box.

Below is the illustration of Scale3x interpolation of small black and white text, twice. As you can see, Scale3x interpolation is quite unusual and absolutely different from nearest neighbour, bilinear and bicubic you know from Photoshop - it tries to keep image sharp and pays attention to diagonals.


Proceed to ScaleNx at GitHub for downloads. For developers: ScaleNx at PyPI.


Move back to main page.