fast_image_resize icon indicating copy to clipboard operation
fast_image_resize copied to clipboard

how does the speed compare with opencv?

Open lucasjinreal opened this issue 2 years ago • 23 comments

how does the speed compare with opencv?

lucasjinreal avatar Jan 12 '23 07:01 lucasjinreal

I have not yet done a benchmark to measure the speed of opencv. I plan to do that after I add multithreading support. Because, as I understand it, opencv already has this feature.

Cykooz avatar Jan 12 '23 09:01 Cykooz

@Cykooz hoping for it!

lucasjinreal avatar Jan 12 '23 11:01 lucasjinreal

It would be nice to add a comparison with libvips.

negezor avatar Jan 18 '23 18:01 negezor

I would also love to see comparison with libvips (not only raw performance, but also peak memory usage)

vhbit avatar Jan 23 '23 11:01 vhbit

With threads turned off, the results look like this:

resizing

benchmark code: https://github.com/bend-n/imenchmark/blob/main/benches/resizing.rs

bend-n avatar Nov 07 '23 00:11 bend-n

@bend-n Thank you for your work.

Cykooz avatar Nov 07 '23 11:11 Cykooz

@bend-n I have only one note about your opencv benchmark. OpenCV doesn't have Lanczos3 implementation. It has only Lanczos4. Lanczoz4 is more complicated (requires more calculations) than Lanczos3.

Cykooz avatar Nov 07 '23 19:11 Cykooz

Oh yeah i forgot to rename the field to lanczos.

bend-n avatar Nov 07 '23 22:11 bend-n

re: libvips, i cant seem to be able to get it to work properly.

bend-n avatar Nov 08 '23 00:11 bend-n

I have found out that OpenCV returns incorrect results if we downscale image with different interpolations. All results, except INTER_AREA, look like INTER_NEAREST. With such results I'll can't make any correct benchmarks.

Image bellow is result of downscaling with different interpolations (result was upscaled x2 for better pixels visibility). OpenCV-resize

Cykooz avatar Nov 09 '23 20:11 Cykooz

Why is that? Is opencv bugged? How is it for upscaling?

bend-n avatar Nov 09 '23 22:11 bend-n

Upscaling looks better. I don't know why downscaling is so bad.

Cykooz avatar Nov 10 '23 06:11 Cykooz

I've understood the reason. OpenCV uses "convolution" with fixed kernel size (it is essentially just Affine Transformations). In this case, downscaling very big image into very small one looks like a result of nearest "interpolation".

fast_image_resize uses convolution with adaptive kernel size. It requires more computations but makes more beter result.

It seems that only INTER_AREA in OpenCV uses real convolution with Box filter and minimal kernel size 1x1px.

Cykooz avatar Nov 10 '23 17:11 Cykooz

@negezor I've done first comparison of libvips with fast_image_resize. I've used libvips v8.12.1 from Ubuntu 22.04 repository. libvips was tested in single-threaded mode with disabled caches.

Nearest Box Bilinear CatmullRom Lanczos3
libvips 21.64 193.67 51.93 78.48 104.58
fir rust 0.86 61.49 97.43 165.89 232.39
fir avx2 - 20.23 21.74 28.14 41.13

Cykooz avatar Nov 10 '23 20:11 Cykooz