Texture2 / app.py
Brijesh000's picture
Create app.py
05ae948 verified
import cv2
import numpy as np
import gradio as gr
# Generate a basic Normal map
def generate_normal_map(image):
# Convert Gradio image (RGB) to grayscale
img = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# Compute gradients using Sobel operators
sobel_x = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
sobel_y = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
# Normalize gradients
sobel_x = cv2.normalize(sobel_x, None, 0, 1, cv2.NORM_MINMAX)
sobel_y = cv2.normalize(sobel_y, None, 0, 1, cv2.NORM_MINMAX)
# Create RGB normal map
height, width = img.shape
normal_map = np.zeros((height, width, 3), dtype=np.uint8)
normal_map[..., 0] = (sobel_x * 255).astype(np.uint8) # Red (X)
normal_map[..., 1] = (sobel_y * 255).astype(np.uint8) # Green (Y)
normal_map[..., 2] = 255 # Blue (Z)
return normal_map
# Set up Gradio interface
interface = gr.Interface(
fn=generate_normal_map,
inputs=gr.Image(type="numpy", label="Upload Texture Image"),
outputs=gr.Image(type="numpy", label="Generated Normal Map"),
title="Material Map Generator",
description="Upload an image to generate a Normal map."
)
# Launch the app
interface.launch()