• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

fatheral/matlab_imresize: Python implementation of MatLab imresize function

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

fatheral/matlab_imresize

开源软件地址(OpenSource Url):

https://github.com/fatheral/matlab_imresize

开源编程语言(OpenSource Language):

Python 100.0%

开源软件介绍(OpenSource Introduction):

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

  • python 2.7
  • numpy

Usage

imresize of uint8 image using scale (e.g. 0.5 or 2):

Img_out = imresize(Img_in, scalar_scale=0.333) # Img_out of type uint8

imresize of uint8 image using shape (e.g. (100, 200)):

Img_out = imresize(Img_in, output_shape=(123, 324)) # Img_out of type uint8

Above examples are working when input image Img_in is of the type uint8. But often the image processing is done in float64, and converted to uint8 only before saving on disk. The following code is for obtaining the same result as doing imresize+imwrite in MatLab for input image of doubles:

import numpy as np
from skimage.io import imsave, imread
from skimage import img_as_float
img_uint8 = imread('test.png')
img_double = img_as_float(img_uint8)
new_img_double = imresize(img_double, output_shape=(123, 324))
imsave('test_double.png', convertDouble2Byte(new_img_double))

Additional information

Actually, the implemented python code was made by re-writing MatLab code toolbox/images/images/imresize.m, and it can't be done without brilliant insight made by S. Sheen about how imresizemex can be implemented (originally, it is binary provided with MatLab distribution): stackoverflow.

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap