Optimal upscaling of images

I seek an optimal method of upscaling an image to a target size that is from 2 to 4 times higher resolution than the original image. I have no control over the starting size as these images are taken on the international space station by cameras available, and the cost considerations preclude sending up higher resolution cameras. However, the analysis software expects much higher resolution so I am left with the task of modifying the original picture to a higher resolution one for analysis.

I have been using the standard internal method of upscaling using DrawPicture

Var p As New Picture(nwidth,nheight,16)
p.DrawPicture(PictureName, 0, 0, g.Width, g.Height, 0, 0, PictureName.Width, PictureName.Height)

I find that this is not optimal as it appears to use linear extrapolation of the pixels. What I seek is something better such as the resizing methods provided by photoshop or pixelmatorpro.

I would welcome suggestions,

You could take a look at the Super2xsai algoritme.
Which can upscale images with extreme high quality without losing quality.
Very impressive stuff.

OpenCV would be a really good tool for this as it has a lot of scaling algorithms and is very fast. Though of course, upscaling means making something from nothing, so it’s never really going to look as good as a natively higher res image (but that’s another conversation).

It’s not super straightforward though, so we started work a while back on getting modern versions of OpenCV working on Xojo.

1 Like

If you have the MBS plugins you could try the PictureMBS scaling methods such as Lanczos or Cubic.

Alternatively, you could use the GraphicsMagick command line tools as they contain different scaling algorithms.

Thanks Keving,

I do have the MBS plugins and will investigate these methods. Thanks for your suggestion. I notice the MBS scaling methods include Lancsos 3 and Lanczos 8 which I assume are the two best options. However, I do not understand what 3 and 8 represent. Are these the order of the polynomials used?

Thanks ChristopheDV,

Where can I find these algorithms? I am happy to give them a try!

From memory, it is the size of the filter.

It might be best to try all of the algorithms as they all have benefits depending on the source content.

Einhugur PictureEffects has functions for upscaling images.

1 Like

Their not like Perfect for Upscaling. Upscaling 2x or 4x is like special thing where you can get much better quality if doing it by those factors and using correct algorithm. Bilinear and Bicubic wont give results on par with that.

Though I do have upscaling on the roadmap somewhere. (At least for Pixel art).

1 Like

This is not trivial and probably not a good candidate for Xojo. There are standalone apps that do this using AI, such as ON1.

Most rescale algorithms like Lanczos, Cubic, … are not that good if you need high quality upscaling.
So if you need very high quality upscaling, Super2xsai or HQ2x is what you are looking for.

I think FFmpeg has Super2xSAI and maybe HQ2x too.

Web page that shows the effect of upscaling a thumbnail using various algorithms:

Perhaps you can use a specialized Application via AppleScript.
Pixelmator Pro is cheap and scriptable.
Here is a sample using “rabbit.jpg” on Desktop folder:

set imageName to "rabbit.jpg"
set imagePath to (path to desktop folder as string) & imageName

set baseName to characters 1 thru ((offset of "." in imageName) - 1) of imageName as string
set suffix to characters ((offset of "." in imageName) + 1) thru (count imageName) of imageName as string
set newname to baseName & ".upscaled." & suffix
set newImagePath to (path to desktop folder as string) & newname

tell application "Pixelmator Pro"
	open alias imagePath
	set scaleFactor to 4
	resize image document 1 width ((width of document 1) * scaleFactor) height ((height of document 1) * scaleFactor) algorithm ml super resolution
	save document 1 in file newImagePath as JPEG
	close document 1 saving no
end tell

This sample does use Pixelmator’s KI based upscaling algorithm. I guess it is hard to get similar results in plain Xojo code that fast

I need to do the upscaling in the app. So far, the best option I have found is using the Lanczos 3 or 8 options provided by the Picture plugin in MBS.