CoolFace
Apppublic

Ashvitta07/Image_preprocessing

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
app.py53 linesDownload Raw Back to root
1import cv22import numpy as np3import gradio as gr4 5def process_image(image):6    # Convert Gradio image (RGB) to OpenCV format (BGR)7    img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)8 9    # Resize10    resized = cv2.resize(img, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_LINEAR)11 12    # Grayscale13    gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)14 15    # Denoising16    denoised = cv2.GaussianBlur(gray, (5, 5), 0)17 18    # Noise removed visualization19    diff = cv2.absdiff(gray, denoised)20 21    # CLAHE enhancement22    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))23    enhanced = clahe.apply(denoised)24 25    # Edge detection26    edges = cv2.Canny(enhanced, 50, 150)27 28    return (29        cv2.cvtColor(resized, cv2.COLOR_BGR2RGB),30        gray,31        denoised,32        diff,33        enhanced,34        edges35    )36 37interface = gr.Interface(38    fn=process_image,39    inputs=gr.Image(type="numpy", label="Upload Image"),40    outputs=[41        gr.Image(label="Resized Image"),42        gr.Image(label="Grayscale Image"),43        gr.Image(label="Denoised Image"),44        gr.Image(label="Noise Removed"),45        gr.Image(label="Enhanced Image (CLAHE)"),46        gr.Image(label="Edge Detection")47    ],48    title="Image Processing Pipeline",49    description="Raw Image → Cleaning → Enhancement → Feature Extraction"50)51 52if __name__ == "__main__":53    interface.launch()