-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,618 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.