# matlab_imresize
Python implementation of MatLab imresize() function.
## Table of contents
1. [Background](#background)
2. [System requirements](#req)
3. [Usage](#usage)
4. [Additional info](#addinfo)
5. [Note](#note)
## Background <a name="background"></a>
In the latest Super Resolution challenges (e.g. see [NTIRE 2017](http://www.vision.ee.ethz.ch/ntire17/)) the downscaling - *bicubic interpolation* - is performed via MatLab imresize() function.
[Track info](http://www.vision.ee.ethz.ch/ntire17/#challenge):
> 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](https://competitions.codalab.org/competitions/16303):
> 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 <a name="req"></a>
* python 2.7
* numpy
## Usage <a name="usage"></a>
imresize of *uint8* image using scale (e.g. 0.5 or 2):
```python
Img_out = imresize(Img_in, scalar_scale=0.333) # Img_out of type uint8
```
imresize of *uint8* image using shape (e.g. (100, 200)):
```python
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:
```python
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 <a name="addinfo"></a>
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](https://stackoverflow.com/users/6073407/s-sheen) about how `imresizemex` can be implemented (originally, it is binary provided with MatLab distribution): [stackoverflow](https://stackoverflow.com/questions/36047357/what-does-imresizemex-do-in-matlab-imresize-function).
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](https://stackoverflow.com/questions/26823140/imresize-trying-to-understand-the-bicubic-interpolation). Also, see [another stackoverflow answer](https://stackoverflow.com/questions/29958670/how-to-use-matlabs-imresize-in-python) about different ways of resizing the image inside python.
## Note <a name="note"></a>
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.
没有合适的资源?快使用搜索试试~ 我知道了~
matlab_imresize:MatLab imresize函数的Python实现
共9个文件
py:3个
png:3个
md:2个
需积分: 14 15 下载量 110 浏览量
2021-05-07
19:55:53
上传
评论
收藏 572KB ZIP 举报
温馨提示
matlab_imresize MatLab imresize()函数的Python实现。 目录 背景 在最新的“超分辨率”挑战中(例如,请参见 ),通过MatLab imresize()函数执行了降尺度(三次三次插值)。 : 轨迹1:bicubic使用bicubic缩小比例(Matlab imresize) ,这是最近的单图像超分辨率文献中最常见的设置之一。 : 为了获得低分辨率图像,我们使用Matlab函数“ imresize”(默认设置)(双三次插值)以及所需的缩小比例:2、3和4。 此外,将经过测试的解决方案的质量(PSNR)与参考解决方案进行了比较-使用三次三次插值进行上采样-使用默认设置的MatLab imresize()函数再次进行此操作。 所有这些导致: 使用MatLab准备火车数据库(缩小高分辨率图像) 参考解决方案(使用三次三次插值法进行放大)也应使用
资源推荐
资源详情
资源评论
收起资源包目录
matlab_imresize-master.zip (9个子文件)
matlab_imresize-master
__init__.py 0B
LICENSE 1KB
imresize.py 5KB
README.md 4KB
test
test_imresize.py 1KB
lena_123x234_uint8.png 51KB
README.md 1KB
lena_512x512.png 463KB
lena_123x234_double.png 51KB
共 9 条
- 1
资源评论
缪之初
- 粉丝: 32
- 资源: 4720
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电影购票系统-Java Web项目
- SPD-Conv-main.zip
- 使用Python和Pygame库创建新年烟花动画效果
- chapter9.zip
- 安居客Python爬虫代码.zip
- 企业可持续发展性数据集,ESG数据集,公司可持续发展性数据(可用于多种企业可持续性研究场景)
- 车辆轨迹自适应预瞄跟踪控制和自适应p反馈联合控制,自适应预苗模型和基于模糊p控制均在simulink中搭建 个人觉得跟踪效果相比模糊pid效果好很多,轨迹跟踪过程,转角控制平滑自然,车速在36到72
- 数据分析-49-客户细分-K-Means聚类分析
- TIA PORTAL V18 UPD5更新包(2024.10最新)-链接地址.txt
- 使用Python和Pygame实现圣诞节动画效果
- 自动驾驶不同工况避障模型(perscan、simulink、carsim联仿),能够避开预设的(静态)障碍物
- 100个情侣头像,唯美手绘情侣头像
- 国际象棋检测10-YOLO(v5至v9)、COCO、CreateML、Paligemma数据集合集.rar
- 2024~2025(1)Oracle数据库技术A卷-22软单、软嵌.doc
- 睡眠健康与生活方式数据集,睡眠和生活习惯关联分析(睡眠影响因素)
- 浪漫节日代码 - 爱心代码、圣诞树代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功