Image Reduction Algorithm

Doe anyone have an implementation of a image size reduction method that will produce smooth size changes.
I have some 512x512 images that need to be reduced to 40x40 (amongst other sizes)
there is a website that will do this (and does a great job), but there is some pre/post image processing that I want to do, not to mention I have to process images one at a time, and would like to do bulk.

Using g.DrawPicture original,0,0,newsize,newsize, 0,0,original.width,original.height produces jagged results

One option that is still pretty fast executing is do the scaling in two stages. You’ll get less sharp results, but execution speed will still be OK compared to pixel wise manipulation. The two stages forces subsampling to occur at two frequencies and “smooths” the result. That’s assuming the targetOS is not doing nearest neighbor scaling.

Original 512 x 512 ----> 160 x 160 —> 40 x 40

I have tried various options such as the one you suggested and none match what the website I found can do…
It produces great results… for me speed is not an issue, but results are

Would you be opposed to using PictureMBS.Scale with a lanczos 3 or cubic filter? That would be the least fuss.

Sometimes the plugin route saves a lot of work.

yup… would rather implement the Lanczos or similar directly…
not in a postion to pay for add-ons, plus I have a fundamental problem with plug-ins (which I have mentioned in the past :slight_smile: )

You can give this declare a try.
I have used it in the past when downscaling an image on a canvas caused it to appear very jagged.

declare sub CGContextSetInterpolationQuality lib "Cocoa" ( context as integer, quality as integer ) CGContextSetInterpolationQuality( g.handle( g.HandleTypeCGContextRef ), 3)

There are a few resources online with source code for different scaling algorithms that shouldn’t take too long to convert to Xojo.

In fact, quite a lot of the PictureMBS.Scale functions originated from my RB code which Christian rewrote in C to improve performance.

The following thread has good information. Towards the end the most effective methods were summarized.

https://forum.xojo.com/9403-scale-quality-of-canvas-control

Preview is good at that, but I do not know if it can be automatized.

[quote=390943:@LangueR]The following thread has good information. Towards the end the most effective methods were summarized.

https://forum.xojo.com/9403-scale-quality-of-canvas-control%5B/quote%5D
lot of good stuff there… just need to wade thru it all… thanks

Fun fact, it can be with Automator.app

[quote=390939:@Jared Feder]You can give this declare a try.
I have used it in the past when downscaling an image on a canvas caused it to appear very jagged.

declare sub CGContextSetInterpolationQuality lib "Cocoa" ( context as integer, quality as integer ) CGContextSetInterpolationQuality( g.handle( g.HandleTypeCGContextRef ), 3)[/quote]

That produced results IDENTICAL to website software I was using… Perfect… thanks