ℹ️ This is a really small piece of “nothing”, but it might save you (and future me) some time!
Recently I started playing around with scikit-image library which is really cool. I found that they had a decent resizing tool, but diving deeper it actually turned out to be really slow.
I’d even go as far as to say that the anti-aliasing (AA) of scikit-image might be too agressive, but you can tune it luckily.
In comparison PIL seems really performant with sane defaults, while OpenCV is a bit low-level and requires a manual gaussian filter to achieve good results.
This is likely not a bottleneck in anyones pipeline, but I love bags of freebies and when running a server on a Raspberry Pi it’s always nice to have some extra performance.
Quick benchmarks:
Please note that this benchmark is not scientific, it’s a simple
timeit(number=100)
, but it’s quite telling anyhow!
Mode | Timer | Person | Chess Board |
---|---|---|---|
Original | N/A | ![]() |
![]() |
PIL.resize(LANCOZ, reducing_gaps=None) | 9.18 | ![]() |
![]() |
PIL.resize(LANCOZ, reducing_gaps=2) | 0.0003 | ![]() |
![]() |
ski.resize(aa=True) | 69.15 | ![]() |
![]() |
cv2.resize(INTER_AREA) | 5.88 | ![]() |
![]() |
cv2.resize(LANCOZ + GaussBlur) | 4.25 | ![]() |
![]() |
cv2.resize(LANCOZ) | 0.033 | ![]() |
![]() |
~Hampus Londögård