Fast image downscaling using integer based arithmetics, described in article:
https://sigmapi-design.com/media/fast_box_filter.pdf
Original code uses custom image container. I have modified the code to suite OpenCV Mat, but did not make any further optimization. There is still lot of space for optimization and modifications for differnet types of image containers.
Also, the similar algorithm (just inverted) can be used for image upscaling.
- C++ compiler (tested on Visual Studio 2017)
- OpenCV
After building, invoke console application:
capDownScale <srcImage> <scale> <showSrc>
Arguments;
- srcImage - source image (mandatory)
- scale - scaling number (mandatory) -> image will be downsampled by factor 1/scale.
- showSrc - show source image (optional): y|n. Default value is n (do not show original image).
Example:
capDownScale VIIRS_3Feb2012_lrg.jpg 17
Note:
Image is scaled proportionally. To downscale image with separated width/height scales, please modify the source code.
Configuration: Intel Core i5-7400 CPU @ 3.00GHz, 16GB RAM.
Os: Windows 10.
Program build: Visual Studio 2017, x86 (32-bit), release mode.
Source image (12000x12000): https://eoimages.gsfc.nasa.gov/images/imagerecords/78000/78314/VIIRS_3Feb2012_lrg.jpg
Scale factor | 1/2 | 1/5 | 1/10 | 1/15 | 1/17 | 1/21 |
Duration (sec) | 0.633 | 0.47 | 0.452 | 0.429 | 0.453 | 0.427 |
[1] Petrić S., Fast Box Filter with Subpixel Accuracy. Sigmapi-Design Paperology (2017).
© Siniša Petrić, www.sigmapi-design.com, MIT license.