fatheral / matlab_imresize

Python implementation of MatLab imresize function
MIT License
154 stars 41 forks source link

matlab_imresize

Python implementation of MatLab imresize() function.

Table of contents

  1. Background
  2. System requirements
  3. Usage
  4. Additional info
  5. Note

    Background

    In the latest Super Resolution challenges (e.g. see NTIRE 2017) the downscaling - bicubic interpolation - is performed via MatLab imresize() function.

Track info:

Track 1: bicubic uses the bicubic downscaling (Matlab imresize), one of the most common settings from the recent single-image super-resolution literature.

More info:

For obtaining the low res images we use the Matlab function "imresize" with default settings (bicubic interpolation) and the desired downscaling factors: 2, 3, and 4.

Moreover, the quality (PSNR) of a tested solution is compared with the reference solution - upsampling with bicubic interpolation - which is done again with MatLab imresize() function with the default settings.

All this leads to:

  1. Preparing train database (downscaling High-Resolution images) using MatLab
  2. Reference solution (upscaling with bicubic interpolation) is also should be done using MatLab

As the most of the Deep Learning code is written under the python, we need to do some additional preprocessing/postprocessing using completely different environment (MatLab), and can't do upscaling/downscaling in-place using simple python functions. As a result, the implemented python imresize() function is done to overcome these difficulties.

System requirements

In fact, if you have OpenCV and have the ability to re-compile it, probably the best solution is to change parameter A inside function interpolateCubic, which is located (at least for release 3.2.0) on line 3129 inside file opencv-3.2.0/modules/imgproc/src/imgwarp.cpp, from -0.75f to -0.5f (the value used in MatLab). Then simply use function cv::resize from OpenCV. For more information please refer to stackoverflow. Also, see another stackoverflow answer about different ways of resizing the image inside python.

Note

Please note that no optimization (aside from preliminary numpy-based vectorizing) was made, so the code can be (and it is) times slower than the original MatLab code.