File size: 2,461 Bytes
fe595ff
4f32010
481f075
042e8d8
5e5bf12
 
 
 
042e8d8
5e5bf12
 
042e8d8
5e5bf12
042e8d8
481f075
 
0c289fa
5e5bf12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
042e8d8
5e5bf12
 
 
 
 
c8253c0
5e5bf12
 
 
 
 
 
 
 
4f32010
5e5bf12
 
 
 
042e8d8
 
5e5bf12
 
042e8d8
5e5bf12
 
 
 
 
c8253c0
042e8d8
5e5bf12
042e8d8
5e5bf12
 
042e8d8
5e5bf12
 
 
 
042e8d8
c8253c0
042e8d8
 
c8253c0
5e5bf12
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import gradio as gr
import cv2
import numpy as np
from PIL import Image
import torch
from torchvision import transforms
import warnings
warnings.filterwarnings('ignore')

# Función simple de upscaling usando OpenCV
def simple_upscale(image, scale_factor=4, method='cubic'):
    """
    Upscaling simple usando interpolación
    """
    if image is None:
        return None
    
    img = np.array(image)
    
    # Métodos de interpolación
    methods = {
        'nearest': cv2.INTER_NEAREST,
        'linear': cv2.INTER_LINEAR,
        'cubic': cv2.INTER_CUBIC,
        'lanczos': cv2.INTER_LANCZOS4
    }
    
    # Calcular nuevo tamaño
    height, width = img.shape[:2]
    new_width = int(width * scale_factor)
    new_height = int(height * scale_factor)
    
    # Upscale
    if len(img.shape) == 3:  # Color
        upscaled = cv2.resize(
            img, 
            (new_width, new_height), 
            interpolation=methods.get(method, cv2.INTER_CUBIC)
        )
    else:  # Grayscale
        upscaled = cv2.resize(
            img,
            (new_width, new_height),
            interpolation=methods.get(method, cv2.INTER_CUBIC)
        )
    
    # Aplicar sharpening
    kernel = np.array([[-1, -1, -1],
                       [-1,  9, -1],
                       [-1, -1, -1]])
    sharpened = cv2.filter2D(upscaled, -1, kernel)
    
    return Image.fromarray(sharpened)

# Interfaz simple
def create_simple_interface():
    with gr.Blocks(title="Mejorador Simple de Imágenes") as app:
        gr.Markdown("# 🖼️ Mejorador de Imágenes Simple")
        
        with gr.Row():
            with gr.Column():
                input_img = gr.Image(type="pil", label="Imagen Original")
                
                scale = gr.Slider(1, 8, 4, step=1, label="Factor de Escala")
                method = gr.Dropdown(
                    ['nearest', 'linear', 'cubic', 'lanczos'],
                    value='cubic',
                    label="Método de Interpolación"
                )
                
                btn = gr.Button("Mejorar", variant="primary")
            
            with gr.Column():
                output_img = gr.Image(type="pil", label="Imagen Mejorada")
        
        btn.click(
            fn=simple_upscale,
            inputs=[input_img, scale, method],
            outputs=output_img
        )
    
    return app

if __name__ == "__main__":
    app = create_simple_interface()
    app.launch()