File size: 1,218 Bytes
28c76d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2adbcc9
 
d511b69
2adbcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cv2
import numpy
import os
import torch
import random
from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer

import gradio as gr
from skimage.restoration import inpaint as p
import torchvision.transforms as transforms


def restore_image(input_image):
    img = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
    threshold_value = 200 
    _, mask = cv2.threshold(img, threshold_value, 255, cv2.THRESH_BINARY)
    channels = cv2.split(img)
    inpaint_channels = []
    for channel in channels:
        inpaint_result = p.inpaint_biharmonic(channel, mask)
        inpaint_channels.append(inpaint_result)

    result_img = cv2.merge(inpaint_channels)
    filename = "output.jpg"
    cv2.imwrite(filename, result_img)    
    return filename


# Define the Gradio app interface
inputs = gr.Image(label="Upload Image")
outputs = gr.Image(label="Restored_Image.")
title = "Image Restoration Using Pix2Pix-GAN"
description = "Restore the Quality of your Old damaged Images To New Looking Images Using Artificial Intelligence"

iface = gr.Interface(fn=restore_image, inputs=inputs, outputs=outputs, title=title, description=description, allow_flagging="never")
iface.launch(inline = False)