documents

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

upscale_image.py (1260B)


      1 
      2 # import cv2
      3 
      4 # def upscale_image(image_path, output_path, model_path):
      5 #     sr = cv2.dnn_superres.DnnSuperResImpl_create()
      6 #     sr.readModel(model_path)
      7 #     sr.setModel("espcn", 4)
      8     
      9 #     image = cv2.imread(image_path)
     10 #     result = sr.upsample(image)
     11 #     cv2.imwrite(output_path, result)
     12 
     13 # if __name__ == "__main__":
     14 #     upscale_image(r"C:\Users\ryout\Downloads\DSCN1883.JPG", "output_espcn.jpg", r"C:\Users\ryout\Downloads\ESPCN_x4.pb")
     15 #
     16 
     17 
     18 import cv2
     19 from realesrgan import RealESRGANer
     20 from basicsr.archs.rrdbnet_arch import RRDBNet
     21 
     22 def super_resolve_ai(image_path, output_path):
     23     model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
     24     
     25     upscaler = RealESRGANer(
     26         scale=4,
     27         model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth',
     28         model=model,
     29         tile=0,
     30         tile_pad=10,
     31         pre_pad=0,
     32         half=False
     33     )
     34     
     35     img = cv2.imread(image_path, cv2.IMREAD_COLOR)
     36     output, _ = upscaler.enhance(img, outscale=4)
     37     cv2.imwrite(output_path, output)
     38 
     39 if __name__ == "__main__":
     40     super_resolve_ai(r"C:\Users\ryout\Downloads\DSCN1883.JPG", "output_realesrgan.jpg")