Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lafith committed Jun 22, 2022
1 parent 671d13d commit a92c0a5
Show file tree
Hide file tree
Showing 5 changed files with 1,618 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SISR Degradation Model

This repo contains the scripts for Degradation model present in the [original repository of BSRGAN by Zhang, Kai and Liang et.al](https://github.com/cszn/BSRGAN). The intention is a standalone repo for the degradation model alone for an easier usage.

```
from dgm import run_degradation
lr, hr = run_degradation('lenna.png', scale=4, patch=128, savefig=True, showfig=True)
```
54 changes: 54 additions & 0 deletions dgm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
@author: Lafith Mattara
@date: 22-06-2022
"""

import utils_blindsr as blindsr
import cv2
import numpy as np
import matplotlib.pyplot as plt
import utils_image as util

def run_degradation(
path, scale=4,
patch=72,
savefig=False, showfig=True
):
'''
path : full path to image
scale : scale factor for dowsampling
patch : patch size of LR
savefig : saves LR-HR as a single image
showfig : show LR-HR as a single image
'''
print("Reading image...")
img = util.imread_uint(path, 3)
img = util.uint2single(img)
print("Running Degradation model...")
lr, hr = blindsr.degradation_bsrgan(
img, sf=scale, lq_patchsize=patch
)
print(
"Input Image : ", img.shape,
"LR :", lr.shape,
"HR : ", hr.shape
)
print("Done!")
if savefig or showfig:
lr_nearest = cv2.resize(
util.single2uint(lr),
(int(scale*lr.shape[1]),
int(scale*lr.shape[0])),
interpolation=0)
img_concat = np.concatenate([lr_nearest, util.single2uint(hr)], axis=1)
if savefig:
util.imsave(img_concat, 'output.png')
if showfig:
plt.imshow(img_concat)
plt.show()
return lr, hr



if __name__ == "__main__":
lr, hr = run_degradation('lenna.png', scale=4, patch=128)
Binary file added lenna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a92c0a5

Please sign in to comment.