Skip to content

feat: add lanczos interpolation implementation#734

Draft
Zekfad wants to merge 3 commits into
brendan-duncan:mainfrom
Zekfad:main
Draft

feat: add lanczos interpolation implementation#734
Zekfad wants to merge 3 commits into
brendan-duncan:mainfrom
Zekfad:main

Conversation

@Zekfad

@Zekfad Zekfad commented May 4, 2025

Copy link
Copy Markdown

based on MIT licensed https://github.com/Megakuul/image_scaler/blob/main/lib/lanczos.dart

resize works good, but I'm not sure if that's correct implementation for getPixelLanczos
it produces good results for down sampling, but upscaling is not good comparing to resize (because of missing precise scale factor?)
i've compared it by using fall back (last else before) instead of dedicated switch case.

@Zekfad
Zekfad marked this pull request as draft May 4, 2025 15:00
@brendan-duncan

Copy link
Copy Markdown
Owner

Nice! I'll take a look at this soon when I get a chance.

@brendan-duncan

Copy link
Copy Markdown
Owner

I did some quick tests and it seems to not deal with alpha correctly, at least for resizing.
copyResize_downscale_cubic
copyResize_downscale_lanczos

@Zekfad

Zekfad commented May 7, 2025

Copy link
Copy Markdown
Author

I'll look into this at the next week, aglo probably needs more tweaking and that alpha issue

@Zekfad Zekfad closed this May 23, 2025
fixes alpha issue, uses oklab linear color space
for better preservation of details
implemented via SIMD operations
for a better performance
@Zekfad Zekfad reopened this May 23, 2025
@Zekfad

Zekfad commented May 23, 2025

Copy link
Copy Markdown
Author

@brendan-duncan fixed alpha issue and made some performance adjustments, I'm very pleased with downscaling results as of now

@Zekfad
Zekfad marked this pull request as ready for review May 23, 2025 01:43
@brendan-duncan

Copy link
Copy Markdown
Owner

Awesome, I'll check it out soon. Thanks!

@Zekfad

Zekfad commented May 23, 2025

Copy link
Copy Markdown
Author

I'm refactoring code right now, is resize.dart even used anywhere beside tests? Its part of src (internal files), but I cant see any references to resize function of itself.

@Zekfad
Zekfad marked this pull request as draft May 23, 2025 16:16
@brendan-duncan

Copy link
Copy Markdown
Owner

resize.dart was a request to be able to do in-place resizing of images, as apposed to copyResize which always makes a copy, and is an exported function.

@Zekfad

Zekfad commented May 23, 2025

Copy link
Copy Markdown
Author

Thanks for reply, missed the export sorry.

I've tried to iterate on algo to fix it for upscaling, but no luck. If you're good with this particular implementation of interpolation being good for downscaling but bad for upscaling I probably should update docs for it and add explicit note.

I lack proper knowledge about image processing, so I think I leave this version for now, maybe in future when I'll have some more time I'll try to dig deeper about convolution filters and fix this implementation.
For future I think it should be implemented similar to this: https://github.com/richgel999/imageresampler/blob/master/resampler.cpp
Its the easiest to understand resampler implementation I've found so far.

Also some related links:
https://clouard.users.greyc.fr/Pantheon/experiments/rescaling/index-en.html
https://entropymine.com/imageworsener/
https://github.com/pixelflinger/lanczos-2d/tree/main
http://www.ericbrasseur.org/gamma.html

@brendan-duncan

Copy link
Copy Markdown
Owner

I'm not forgetting about this, just been busy with the family

@Zekfad

Zekfad commented May 25, 2025

Copy link
Copy Markdown
Author

No worries about that!

I've also found some issues with downscaling very big images to a very small, such as 1024->64, alpha looks inverted for some reason.

Can't give any dates, due to work, but I plan on changing this to a different approach - make a new file and implement convolution based scaling as in links I mentioned, so I think you can ignore pr this for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants