| import streamlit as st
|
| import numpy as np
|
| import cv2
|
| from tensorflow.keras.models import load_model
|
|
|
|
|
| st.set_page_config(page_title="CNN Boundary Detector", layout="centered")
|
|
|
|
|
| st.markdown("""
|
| <style>
|
| .stImage > img {
|
| border-radius: 8px;
|
| border: 1px solid #ddd;
|
| }
|
| /* Sütunlar arasındaki boşluğu ve hizalamayı koru */
|
| [data-testid="stHorizontalBlock"] {
|
| align-items: center;
|
| }
|
| </style>
|
| """, unsafe_allow_html=True)
|
|
|
| @st.cache_resource
|
| def load_my_model():
|
|
|
| return load_model("cnn_segmentation_model.keras", compile=False)
|
|
|
| model = load_my_model()
|
|
|
|
|
| st.markdown("<h1 style='text-align: center;'>🎯 Boundary Detection System</h1>", unsafe_allow_html=True)
|
| st.markdown("<h3 style='text-align: center; color: gray;'>Kenar ve Sınır Tespit Sistemi</h3>", unsafe_allow_html=True)
|
| st.write("---")
|
|
|
|
|
| uploaded_file = st.file_uploader("Upload Image / Resim Yükleyin", type=["jpg", "jpeg", "png"])
|
|
|
| if uploaded_file is not None:
|
|
|
| file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| img = cv2.imdecode(file_bytes, 1)
|
| img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
|
|
|
| img_input = cv2.resize(img_rgb, (168, 168)) / 255.0
|
| img_input = np.expand_dims(img_input, axis=0)
|
|
|
| with st.spinner('Analyzing... / Analiz ediliyor...'):
|
| pred = model.predict(img_input, verbose=0)[0]
|
| mask = pred.squeeze()
|
|
|
|
|
| mask_norm = (mask - mask.min()) / (mask.max() - mask.min() + 1e-7)
|
| mask_255 = (mask_norm * 255).astype(np.uint8)
|
|
|
|
|
| mask_resized = cv2.resize(mask_255, (img_rgb.shape[1], img_rgb.shape[0]))
|
|
|
|
|
| overlay = img_rgb.copy()
|
|
|
| overlay[mask_resized > 120] = [0, 255, 0]
|
| final_blend = cv2.addWeighted(img_rgb, 0.7, overlay, 0.3, 0)
|
|
|
|
|
| col1, col2 = st.columns(2)
|
|
|
| with col1:
|
| st.markdown("<p style='text-align: center; font-weight: bold;'>Original / Orijinal</p>", unsafe_allow_html=True)
|
| st.image(img_rgb, use_container_width=True)
|
|
|
| with col2:
|
| st.markdown("<p style='text-align: center; font-weight: bold;'>Prediction / Tahmin</p>", unsafe_allow_html=True)
|
| st.image(final_blend, use_container_width=True)
|
|
|
|
|
| st.write("---")
|
| with st.expander("Show Binary Mask / İkili Maskeyi Göster"):
|
| st.image(mask_resized, width=400, caption="Grayscale Output")
|
|
|
| else:
|
| st.info("Waiting for image upload... / Resim yüklenmesi bekleniyor...") |