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