# Optimal upscaling of images

**URL:** <https://forum.xojo.com/t/optimal-upscaling-of-images/70082>\
**Category:** General\
**Created:** [May 4, 2022, 7:21pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082 "2022-05-04T19:21:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Birge](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_birge/32/210_2.png) [@Robert\_Birge](https://forum.xojo.com/u/Robert_Birge)\
**Post date:** [May 4, 2022, 7:21pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/1 "2022-05-04T19:21:54Z")

</div>

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,  
Thanks,  
Bob

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [May 4, 2022, 8:01pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/2 "2022-05-04T20:01:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Perry\_Paolantonio](https://forum.xojo.com/user_avatar/forum.xojo.com/perry_paolantonio/32/4353_2.png) [@Perry\_Paolantonio](https://forum.xojo.com/u/Perry_Paolantonio)\
**Post date:** [May 4, 2022, 8:12pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/3 "2022-05-04T20:12:31Z")

</div>

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.

> [@Bringing OpenCV to Xojo (again)](https://forum.xojo.com/t/bringing-opencv-to-xojo-again/70085):
>
> Unfortunately, OpenCV is C++ and you can’t use it in Xojo. However… While it is not yet done, we started work over a year ago to wrap OpenCV 4.5 in a plain-C library so that it could be used in Xojo. In fact, there actually two projects: OpenCV-C (The C++ → C library; currently on Github but private since it’s not done) Xojo-OpenCV-C (also private on github as it’s incomplete) The Xojo project aims to make OpenCV-C functionality available as native Xojo code. But to be honest, development on…

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 4, 2022, 8:19pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/5 "2022-05-04T20:19:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robert\_Birge](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_birge/32/210_2.png) [@Robert\_Birge](https://forum.xojo.com/u/Robert_Birge)\
**Post date:** [May 4, 2022, 8:29pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/6 "2022-05-04T20:29:05Z")

</div>

> [@keving](#):
>
> If you have the MBS plugins you could try the PictureMBS scaling methods such as Lanczos or Cubic.

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?

---

<div class="post-metadata">

**Author:** ![Robert\_Birge](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_birge/32/210_2.png) [@Robert\_Birge](https://forum.xojo.com/u/Robert_Birge)\
**Post date:** [May 4, 2022, 8:30pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/7 "2022-05-04T20:30:51Z")

</div>

> [@ChristopheDV](#):
>
> You could take a look at the Super2xsai algoritme.

Thanks ChristopheDV,

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

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 4, 2022, 8:34pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/8 "2022-05-04T20:34:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [May 5, 2022, 12:37am UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/9 "2022-05-05T00:37:02Z")

</div>

Einhugur PictureEffects has functions for upscaling images.

---

<div class="post-metadata">

**Author:** ![Björn\_Eiríksson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@Björn\_Eiríksson](https://forum.xojo.com/u/Bj%C3%B6rn_Eir%C3%ADksson)\
**Post date:** [May 5, 2022, 6:07am UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/10 "2022-05-05T06:07:10Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Nicholas\_Loveday](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@Nicholas\_Loveday](https://forum.xojo.com/u/Nicholas_Loveday)\
**Post date:** [May 5, 2022, 6:43am UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/11 "2022-05-05T06:43:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ChristopheDV](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@ChristopheDV](https://forum.xojo.com/u/ChristopheDV)\
**Post date:** [May 5, 2022, 11:43am UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/12 "2022-05-05T11:43:02Z")

</div>

> [@ChristopheDV](#):
>
> Super2xsai

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.

> **[Pixel-art scaling algorithms](https://en.wikipedia.org/wiki/Pixel-art_scaling_algorithms)**
>
> Pixel art scaling algorithms are graphical filters that attempt to enhance the appearance of hand-drawn 2D pixel art graphics. These algorithms are a form of automatic image enhancement. Pixel art scaling algorithms employ methods significantly different than the common methods of image rescaling, which have the goal of preserving the appearance of images.
> As pixel art graphics are commonly used at very low resolutions, they employ careful coloring of individual pixels. This results in graphics ...

I think FFmpeg has Super2xSAI and maybe HQ2x too.

---

<div class="post-metadata">

**Author:** ![kevin\_g](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kevin\_g](https://forum.xojo.com/u/kevin_g)\
**Post date:** [May 5, 2022, 12:19pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/13 "2022-05-05T12:19:55Z")

</div>

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

> **[Comparison gallery of image scaling algorithms](https://en.wikipedia.org/wiki/Comparison_gallery_of_image_scaling_algorithms)**
>
> This gallery shows the results of numerous image scaling algorithms.
> An image size can be changed in several ways. Consider resizing a 160x160 pixel photo to the following 40x40 pixel thumbnail and then scaling the thumbnail to a 160x160 pixel image. Also consider doubling the size of the following image containing text.
> One of the simpler ways of increasing the size, replacing every pixel with a number of pixels of the same color. The resulting image is larger than the original, and preserves ...

---

<div class="post-metadata">

**Author:** ![TomE1](https://forum.xojo.com/user_avatar/forum.xojo.com/tome1/32/1940_2.png) [@TomE1](https://forum.xojo.com/u/TomE1)\
**Post date:** [May 5, 2022, 12:51pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/14 "2022-05-05T12:51:57Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Robert\_Birge](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_birge/32/210_2.png) [@Robert\_Birge](https://forum.xojo.com/u/Robert_Birge)\
**Post date:** [May 5, 2022, 2:55pm UTC](https://forum.xojo.com/t/optimal-upscaling-of-images/70082/15 "2022-05-05T14:55:23Z")

</div>

> [@TomE1](#):
>
> Perhaps you can use a specialized Application via AppleScript.

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.
