diff --git a/CARN/progressive/README.md b/CARN/progressive/README.md index ce9b576..ac1416b 100644 --- a/CARN/progressive/README.md +++ b/CARN/progressive/README.md @@ -3,6 +3,6 @@ Converted from **official** [nmhkahn/NTIRE2018](https://github.com/nmhkahn/NTIRE --- ### Reference -**[1] Ahn, N., Kang, B., & Sohn, K. A. (2018). Image Super-resolution via Progressive Cascading Residual Network. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018_workshops/papers/w13/Ahn_Image_Super-Resolution_via_CVPR_2018_paper.pdf) [[Code]](https://github.com/nmhkahn/NTIRE2018)** +**[1] Ahn, N., Kang, B., & Sohn, K. A. (2018). [Image Super-resolution via Progressive Cascading Residual Network](https://ieeexplore.ieee.org/document/8575275). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018_workshops/papers/w13/Ahn_Image_Super-Resolution_via_CVPR_2018_paper.pdf) [[Code]](https://github.com/nmhkahn/NTIRE2018)** -[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results. In proceedings of the IEEE Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) +[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). [NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results](https://ieeexplore.ieee.org/document/8575282/). In the IEEE/CVF Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) diff --git a/DBPN/README.md b/DBPN/README.md index afd3960..4ada30b 100644 --- a/DBPN/README.md +++ b/DBPN/README.md @@ -3,6 +3,6 @@ Converted from **official** [alterzero/DBPN-caffe](https://github.com/alterzero/ --- ### Reference -**[1] Haris, M., Shakhnarovich, G., & Ukita, N. (2018). Deep Back-Projection Networks For Super-Resolution. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. [[PDF]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN_cvpr2018_final.pdf) [[Code-Caffe]](https://github.com/alterzero/DBPN-caffe) [[Code-PyTorch]](https://github.com/alterzero/DBPN-Pytorch) [[Supplementary Material]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN_cvpr2018_supp_material.pdf) [[Project]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN.html)** +**[1] Haris, M., Shakhnarovich, G., & Ukita, N. (2018). [Deep Back-Projection Networks For Super-Resolution](https://ieeexplore.ieee.org/document/8578277/). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition. [[PDF]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN_cvpr2018_final.pdf) [[Code-Caffe]](https://github.com/alterzero/DBPN-caffe) [[Code-PyTorch]](https://github.com/alterzero/DBPN-Pytorch) [[Supplementary Material]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN_cvpr2018_supp_material.pdf) [[Project]](https://www.toyota-ti.ac.jp/Lab/Denshi/iim/members/muhammad.haris/projects/DBPN.html)** -[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results. In proceedings of the IEEE Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) +[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). [NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results](https://ieeexplore.ieee.org/document/8575282/). In the IEEE/CVF Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) diff --git a/IDN/README.md b/IDN/README.md index a27689c..b09c8d0 100644 --- a/IDN/README.md +++ b/IDN/README.md @@ -3,4 +3,4 @@ Converted from **official** [Zheng222/IDN-Caffe](https://github.com/Zheng222/IDN --- ### Reference -[1] Hui, Z., Wang, X. & Gao, X. (2018). Fast and Accurate Single Image Super-Resolution via Information Distillation Network. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018/papers/Hui_Fast_and_Accurate_CVPR_2018_paper.pdf) [[Code]](https://github.com/Zheng222/IDN-Caffe) [[Poster]](https://github.com/Zheng222/IDN-Caffe/blob/2bcc23e4f66684cb7e1fbb3ceb4a957f830b83e6/files/cvpr18_poster.pdf) +[1] Hui, Z., Wang, X. & Gao, X. (2018). [Fast and Accurate Single Image Super-Resolution via Information Distillation Network](https://ieeexplore.ieee.org/document/8578180/). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018/papers/Hui_Fast_and_Accurate_CVPR_2018_paper.pdf) [[Code]](https://github.com/Zheng222/IDN-Caffe) [[Poster]](https://github.com/Zheng222/IDN-Caffe/blob/2bcc23e4f66684cb7e1fbb3ceb4a957f830b83e6/files/cvpr18_poster.pdf) diff --git a/ProSR/README.md b/ProSR/README.md index 21f1c74..07624e9 100644 --- a/ProSR/README.md +++ b/ProSR/README.md @@ -3,6 +3,6 @@ Converted from **official** [fperazzi/proSR](https://github.com/fperazzi/proSR/t --- ### Reference -**[1] Wang, Y., Perazzi, F., McWilliams, B., Sorkine-Hornung, A., Sorkine-Hornung, O., & Schroers, C. (2018). A Fully Progressive Approach to Single-Image Super-Resolution. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://igl.ethz.ch/projects/prosr/prosr-cvprw-2018-wang-et-al.pdf) [[Code]](https://github.com/fperazzi/proSR) [[Supplementary Material]](http://igl.ethz.ch/projects/prosr/prosr-supplemental.pdf) [[Video]](http://igl.ethz.ch/projects/prosr/prosr-video.mp4) [[Project]](http://igl.ethz.ch/projects/prosr/)** +**[1] Wang, Y., Perazzi, F., McWilliams, B., Sorkine-Hornung, A., Sorkine-Hornung, O., & Schroers, C. (2018). [A Fully Progressive Approach to Single-Image Super-Resolution](https://ieeexplore.ieee.org/document/8575284/). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://igl.ethz.ch/projects/prosr/prosr-cvprw-2018-wang-et-al.pdf) [[Code]](https://github.com/fperazzi/proSR) [[Supplementary Material]](http://igl.ethz.ch/projects/prosr/prosr-supplemental.pdf) [[Video]](http://igl.ethz.ch/projects/prosr/prosr-video.mp4) [[Project]](http://igl.ethz.ch/projects/prosr/)** -[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results. In proceedings of the IEEE Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) +[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). [NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results](https://ieeexplore.ieee.org/document/8575282/). In the IEEE/CVF Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) diff --git a/RDN/Residual-Dense-Network-Caffe@xueshengke/README.md b/RDN/Residual-Dense-Network-Caffe@xueshengke/README.md index d723a48..9c66907 100644 --- a/RDN/Residual-Dense-Network-Caffe@xueshengke/README.md +++ b/RDN/Residual-Dense-Network-Caffe@xueshengke/README.md @@ -3,4 +3,4 @@ Converted from [xueshengke/Residual-Dense-Network-Caffe](https://github.com/xues --- ### Reference -[1] Zhang, Y., Tian, Y., Kong, Y., Zhong, B. & Fu, Y. (2018). Residual Dense Network for Image Super-Resolution. In the IEEE Conference on Computer Vision and Pattern Recognition. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018/papers/Zhang_Residual_Dense_Network_CVPR_2018_paper.pdf) [[Code]](https://github.com/yulunzhang/RDN) +[1] Zhang, Y., Tian, Y., Kong, Y., Zhong, B. & Fu, Y. (2018). [Residual Dense Network for Image Super-Resolution](https://ieeexplore.ieee.org/document/8578360/). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition. [[PDF]](http://openaccess.thecvf.com/content_cvpr_2018/papers/Zhang_Residual_Dense_Network_CVPR_2018_paper.pdf) [[Code]](https://github.com/yulunzhang/RDN) diff --git a/SESR/README.md b/SESR/README.md index 7a90f20..ae5880d 100644 --- a/SESR/README.md +++ b/SESR/README.md @@ -3,4 +3,4 @@ Converted from **official** [opteroncx/SESR](https://github.com/opteroncx/SESR/t --- ### Reference -[1] Cheng, X., Li, X., Yang, J. & Tai, Y. (2018). SESR: Single Image Super Resolution with Recursive Squeeze and Excitation Networks. In proceedings of International Conference on Pattern Recognition. [[PDF]](https://arxiv.org/pdf/1801.10319) [[Code]](https://github.com/opteroncx/SESR) +[1] Cheng, X., Li, X., Yang, J. & Tai, Y. (2018). [SESR: Single Image Super Resolution with Recursive Squeeze and Excitation Networks](https://ieeexplore.ieee.org/document/8546130/). International Conference on Pattern Recognition. [[PDF]](https://arxiv.org/pdf/1801.10319) [[Code]](https://github.com/opteroncx/SESR) diff --git a/TSCN/README.md b/TSCN/README.md index 5d953a9..96d7509 100644 --- a/TSCN/README.md +++ b/TSCN/README.md @@ -3,4 +3,4 @@ Converted from **official** [Zheng222/TSCN](https://github.com/Zheng222/TSCN/com --- ### Reference -[1] Hui, Z., Wang, X., & Gao, X. (2018). Two-Stage Convolutional Network for Image Super-Resolution. In proceedings of International Conference on Pattern Recognition. [[PDF]](https://github.com/Zheng222/TSCN/blob/20818c148a6f02a0d5e7c75553528f52dbebcf6a/files/TSCN.pdf) [[Code]](https://github.com/Zheng222/TSCN) [[Poster]](https://github.com/Zheng222/TSCN/raw/master/files/icpr18_poster.pdf) \ No newline at end of file +[1] Hui, Z., Wang, X., & Gao, X. (2018). [Two-Stage Convolutional Network for Image Super-Resolution](https://ieeexplore.ieee.org/document/8545648/). International Conference on Pattern Recognition. [[PDF]](https://github.com/Zheng222/TSCN/blob/20818c148a6f02a0d5e7c75553528f52dbebcf6a/files/TSCN.pdf) [[Code]](https://github.com/Zheng222/TSCN) [[Poster]](https://github.com/Zheng222/TSCN/raw/master/files/icpr18_poster.pdf) \ No newline at end of file diff --git a/WDSR/wdsr@krasserm/README.md b/WDSR/wdsr@krasserm/README.md index a5f9697..eeec25a 100644 --- a/WDSR/wdsr@krasserm/README.md +++ b/WDSR/wdsr@krasserm/README.md @@ -5,4 +5,4 @@ Converted from [krasserm/wdsr](https://github.com/krasserm/wdsr/tree/4701c31b8fb ### Reference **[1] Yu, J. H., Fan, Y. C., Yang, J. C., Xu, N., Wang, Z. W., Wang, X. C. & Huang, T. (2018). Wide Activation for Efficient and Accurate Image Super-Resolution. arXiv preprint arXiv:1808.08718. [[PDF]](https://arxiv.org/pdf/1808.08718) [[Code]](https://github.com/JiahuiYu/wdsr_ntire2018)** -[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results. In proceedings of the IEEE Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) +[2] Timofte, R., Gu, S. H., Wu, J. Q., Van Gool, L., Zhang, L., Yang, M. H., ... & Fu, L. Z. (2018). [NTIRE 2018 Challenge on Single Image Super-Resolution: Methods and Results](https://ieeexplore.ieee.org/document/8575282/). In the IEEE/CVF Converence on Computer Vision and Pattern Recognition Workshops. [[PDF]](http://people.ee.ethz.ch/~timofter/publications/NTIRE2018_SR_report_CVPRW-2018.pdf) [[Project]](http://www.vision.ee.ethz.ch/ntire18/#challenge) diff --git a/linear_method/bicubic_2x-0000.params b/linear_method/bicubic_2x-0000.params new file mode 100644 index 0000000..1d0b01c Binary files /dev/null and b/linear_method/bicubic_2x-0000.params differ diff --git a/linear_method/bicubic_2x-symbol.json b/linear_method/bicubic_2x-symbol.json new file mode 100644 index 0000000..4eae7e9 --- /dev/null +++ b/linear_method/bicubic_2x-symbol.json @@ -0,0 +1,83 @@ +{ + "nodes": [ + { + "op": "null", + "name": "data", + "inputs": [] + }, + { + "op": "Pad", + "name": "pad0", + "attrs": { + "mode": "edge", + "pad_width": "(0, 0, 0, 0, 2, 2, 0, 0)" + }, + "inputs": [[0, 0, 0]] + }, + { + "op": "null", + "name": "bicubic_2x_h_weight", + "attrs": { + "kernel": "(8, 1)", + "no_bias": "True", + "num_filter": "1", + "num_group": "1", + "pad": "(7, 0)", + "stride": "(2, 1)" + }, + "inputs": [] + }, + { + "op": "Deconvolution", + "name": "bicubic_2x_h", + "attrs": { + "kernel": "(8, 1)", + "no_bias": "True", + "num_filter": "1", + "num_group": "1", + "pad": "(7, 0)", + "stride": "(2, 1)" + }, + "inputs": [[1, 0, 0], [2, 0, 0]] + }, + { + "op": "Pad", + "name": "pad1", + "attrs": { + "mode": "edge", + "pad_width": "(0, 0, 0, 0, 0, 0, 2, 2)" + }, + "inputs": [[3, 0, 0]] + }, + { + "op": "null", + "name": "bicubic_2x_w_weight", + "attrs": { + "kernel": "(1, 8)", + "no_bias": "True", + "num_filter": "1", + "num_group": "1", + "pad": "(0, 7)", + "stride": "(1, 2)" + }, + "inputs": [] + }, + { + "op": "Deconvolution", + "name": "bicubic_2x_w", + "attrs": { + "kernel": "(1, 8)", + "no_bias": "True", + "num_filter": "1", + "num_group": "1", + "pad": "(0, 7)", + "stride": "(1, 2)" + }, + "inputs": [[4, 0, 0], [5, 0, 0]] + } + ], + "arg_nodes": [0, 2, 5], + "node_row_ptr": [0, 1, 2, 3, 4, 5, 6, 7], + "heads": [[6, 0, 0]], + "attrs": {"mxnet_version": ["int", 10300]} +} \ No newline at end of file diff --git a/linear_method/example_produce_resizer.py b/linear_method/example_produce_resizer.py new file mode 100644 index 0000000..7e4f147 --- /dev/null +++ b/linear_method/example_produce_resizer.py @@ -0,0 +1,71 @@ +import mxnet as mx +from resize_weight import resize_weight + +# a script that produces a (center-aligned) linear interpolation resizer in the form of CNN in MXNet + +# params +scale = 2 +kernel = 'bicubic' +channels = 1 +downsample = False + +if not downsample: + name = '{}_{}x'.format(kernel, scale) + + weight_1d = resize_weight(scale=scale, kernel=kernel) + width = len(weight_1d) + taps = (width + 1) // (2 * scale) + + # tries to fix the boundary condition via external padding, but the value here might not be accurate + pad = scale // 2 + (2 * taps - 1) * scale + + # Defining the network + # Since the interpolations are separable, we implemented them via spatial separable convolutions + # It's straightforward to modify the code to obtain a single convolution implementation + data = mx.symbol.Variable('data') # assumes NCHW data format + upsample_h = mx.symbol.pad(data, mode='edge', pad_width=(0, 0, 0, 0, taps, taps, 0, 0)) + upsample_h = mx.symbol.Deconvolution(upsample_h, kernel=(width, 1), stride=(scale, 1), pad=(pad, 0), + num_filter=channels, num_group=channels, no_bias=True, name='{}_h'.format(name)) + upsample_w = mx.symbol.pad(upsample_h, mode='edge', pad_width=(0, 0, 0, 0, 0, 0, taps, taps)) + upsample_w = mx.symbol.Deconvolution(upsample_w, kernel=(1, width), stride=(1, scale), pad=(0, pad), + num_filter=channels, num_group=channels, no_bias=True, name='{}_w'.format(name)) + + # Loading weights + net = mx.gluon.SymbolBlock(outputs=upsample_w, inputs=data) + net_params = net.collect_params() + net_params['{}_h_weight'.format(name)]._load_init(mx.nd.array(weight_1d.reshape((1, 1, width, 1))), ctx=mx.cpu()) + net_params['{}_w_weight'.format(name)]._load_init(mx.nd.array(weight_1d.reshape((1, 1, 1, width))), ctx=mx.cpu()) + net.hybridize() + test_data = mx.nd.ones((1, channels, 96, 96)) + net.forward(test_data) + + # Output + net.export(name) + +else: + name = '{}_{}x_downsample'.format(kernel, scale) + + weight_1d = resize_weight(scale=scale, kernel=kernel, downsample=True) + width = len(weight_1d) + taps = (width + 1) // (2 * scale) + pad = scale // 2 + (2 * taps - 1) * scale + + data = mx.symbol.Variable('data') + upsample_h = mx.symbol.pad(data, mode='edge', pad_width=(0, 0, 0, 0, 2 * taps - 1, 2 * taps, 0, 0)) + upsample_h = mx.symbol.Deconvolution(upsample_h, kernel=(width, 1), stride=(scale, 1), pad=(pad, 0), + num_filter=channels, num_group=channels, no_bias=True, name='{}_h'.format(name)) + upsample_w = mx.symbol.pad(upsample_h, mode='edge', pad_width=(0, 0, 0, 0, 0, 0, 2 * taps - 1, 2 * taps - 1)) + upsample_w = mx.symbol.Deconvolution(upsample_w, kernel=(1, width), stride=(1, scale), pad=(0, pad), + num_filter=channels, num_group=channels, no_bias=True, name='{}_w'.format(name)) + + net = mx.gluon.SymbolBlock(outputs=upsample_w, inputs=data) + net_params = net.collect_params() + net_params['{}_h_weight'.format(name)]._load_init(mx.nd.array(weight_1d.reshape((1, 1, width, 1))), ctx=mx.cpu()) + net_params['{}_w_weight'.format(name)]._load_init(mx.nd.array(weight_1d.reshape((1, 1, 1, width))), ctx=mx.cpu()) + + net.hybridize() + + test_data = mx.nd.ones((1, channels, 96, 96)) + net.forward(test_data) + + net.export(name) \ No newline at end of file diff --git a/linear_method/resize_weight.py b/linear_method/resize_weight.py new file mode 100644 index 0000000..511215a --- /dev/null +++ b/linear_method/resize_weight.py @@ -0,0 +1,114 @@ +import numpy as np +import functools + +_vectorize_fp64 = functools.partial(np.vectorize, otypes=[np.float64]) + +@_vectorize_fp64 +def box(x): + """matlab.images.internal.resize.box""" + + return -0.5 <= x < 0.5 + +@_vectorize_fp64 +def triangle(x): + """matlab.images.internal.resize.triangle""" + + return (x + 1) * (-1 <= x < 0) + (1 - x) * (0 <= x <= 1) + +@_vectorize_fp64 +def cubic(x): + """matlab.images.internal.resize.cubic""" + + absx = abs(x) + absx2 = absx ** 2 + absx3 = absx ** 3 + + return ((1.5 * absx3 - 2.5 * absx2 + 1) * (absx <= 1) + + (-0.5 * absx3 + 2.5 * absx2 - 4 * absx + 2) * (1 < absx <= 2)) + +@_vectorize_fp64 +def lanczos2(x): + """matlab.images.internal.resize.lanczos2""" + + eps = np.finfo(np.float64).eps + + return (np.sin(np.pi * x) * np.sin(np.pi * x / 2) + eps) / ((np.pi ** 2 * x ** 2 / 2) + eps) * (abs(x) < 2) + +@_vectorize_fp64 +def lanczos3(x): + """matlab.images.internal.resize.lanczos2""" + + eps = np.finfo(np.float64).eps + + return (np.sin(np.pi * x) * np.sin(np.pi * x / 3) + eps) / ((np.pi ** 2 * x ** 2 / 3) + eps) * (abs(x) < 3) + + +def resize_weight(scale=2, kernel=None, downsample=False): + """A function that outputs weights for a specified resizer + + This function assumes center-aligned interpolation. + + Args: + scale: (int) Resize factor. The type of value for downscale is also an integer. + Default is 2. + + kernel: (str) Interpolation method. + Available methods: box, bilinear(triangle), bicubic(cubic), lanczos2, lanczos3. + Default is 'bicubic'. + + downsample: (bool) Whether the weights are used for downsample instead of upsample. + Default is False. + + Ref: + [1] P. Getreuer. (2011). Linear Methods for Image Interpolation. Image Processing On Line, 1, pp. 238–259. + + """ + + if not isinstance(scale, int) or scale <= 1: + raise ValueError('\'scale\' must be an integer greater than 1!') + + if kernel is None: + kernel = 'cubic' + else: + kernel = kernel.lower() + + if kernel == 'bicubic': + kernel = 'cubic' + + if kernel == 'bilinear': + kernel = 'triangle' + + if kernel in ['box', 'triangle']: + taps = 1 + elif kernel in ['cubic', 'lanczos2']: + taps = 2 + elif kernel in ['lanczos3']: + taps = 3 + else: + raise ValueError('Unknown resize kernel {}!'.format(kernel)) + + func = eval(f'{kernel}') + + if scale % 2 == 0: # scale is even + kernel_width = 2 * scale * taps + weight_1d = np.empty(kernel_width, dtype=np.float64) + weight_1d[kernel_width//2:] = func([(2 * i + 1) / (2 * scale) for i in range(kernel_width // 2)]) + weight_1d[:kernel_width//2] = weight_1d[:kernel_width//2-1:-1] # mirror + + else: # scale is odd + kernel_width = 2 * scale * taps - 1 + weight_1d = np.empty(kernel_width, dtype=np.float64) + weight_1d[kernel_width//2:] = func([(i / scale) for i in range(kernel_width // 2 + 1)]) + weight_1d[:kernel_width//2] = weight_1d[:kernel_width//2:-1] # mirror + + # kernel normalization: + for i in range(scale): + weight_1d[i::scale] /= weight_1d[i::scale].sum() + + if downsample: + weight_1d /= scale + + if kernel in ['box']: + weight_1d = weight_1d[scale//2:-scale//2] + + return weight_1d diff --git a/xUnit/README.md b/xUnit/README.md index dd695e1..9feca45 100644 --- a/xUnit/README.md +++ b/xUnit/README.md @@ -3,7 +3,7 @@ Converted from **official** [kligvasser/xUnit](https://github.com/kligvasser/xUn --- ### Reference -**[1] Kligvasser, I., Shaham, T. R., & Michaeli, T. (2018). xUnit: Learning a Spatial Activation Function for Efficient Image Restoration. In proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. [[PDF]](https://tomer.net.technion.ac.il/files/2018/03/xUnit_CameraReady.pdf) [[Code]](https://github.com/kligvasser/xUnit)** +**[1] Kligvasser, I., Shaham, T. R., & Michaeli, T. (2018). [xUnit: Learning a Spatial Activation Function for Efficient Image Restoration](https://ieeexplore.ieee.org/document/8578356/). In the IEEE/CVF Conference on Computer Vision and Pattern Recognition. [[PDF]](https://tomer.net.technion.ac.il/files/2018/03/xUnit_CameraReady.pdf) [[Code]](https://github.com/kligvasser/xUnit)** [2] Zhang, K., Zuo, W., Chen, Y., Meng, D., & Zhang, L. (2017). [Beyond a Gaussian Denoiser: Residual Learning of Deep CNN for Image Denoising](https://ieeexplore.ieee.org/document/7839189/). IEEE Transactions on Image Processing, 26(7), 3142-3155. [[PDF]](https://arxiv.org/pdf/1608.03981) [[Code]](https://github.com/cszn/DnCNN)