| |
| import gradio as gr |
| import cv2 as cv |
| import numpy as np |
| import matplotlib.pyplot as plt |
|
|
| |
| def convert_to_fft(image): |
| if image.ndim == 3: |
| image = cv.cvtColor(image, cv.COLOR_BGR2GRAY) |
| f = np.fft.fft2(image) |
| fshift = np.fft.fftshift(f) |
| magnitude_spectrum = 20 * np.log(np.abs(fshift) + 1) |
| return magnitude_spectrum |
|
|
| def page_transformasi(): |
| gr.HTML(""" |
| <div style="text-align:center; padding:20px;"> |
| <h1 style="font-size:72px;">Transformasi Dasar</h1> |
| <p style="font-size:36px;">Transformasi Fourier pada citra</p> |
| </div> |
| """) |
| gr.Button("Kembali ke Beranda", link="/", variant="primary") |
| def page_home(): |
| with gr.Blocks() as home: |
| gr.HTML(""" |
| <div style="text-align:center; padding:20px;"> |
| <h1 style="font-size:72px;">Frequency Domain Demo</h1> |
| <p style="font-size:36px;">Eksperimen image processing di domain frekuensi</p> |
| </div> |
| """) |
| gr.Button("1. Transformasi Dasar", link="/transformasi", variant="primary") |
| gr.Button("2. Filtering", link="/filtering", variant="primary") |
| gr.Button("3. Masking", link="/masking", variant="primary") |
| gr.Button("4. Phase vs Magnitude", link="/phase-magnitude", variant="primary") |
| |
| return home |
|
|
| def build_app(): |
| with gr.Blocks() as demo: |
| page_home() |
| with demo.route("Transformasi Dasar", "/transformasi"): |
| pass |
| with demo.route("Filtering", "/filtering"): |
| pass |
| with demo.route("Masking", "/masking"): |
| pass |
| with demo.route("Phase vs Magnitude", "/phase-magnitude"): |
| pass |
| return demo |
|
|
| app = build_app() |
| app.launch(share=True) |