Spaces:
Runtime error
Runtime error
Commit
·
5bda096
1
Parent(s):
e51e707
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def brighten_image(image, amount):
|
| 8 |
+
img_bright = cv2.convertScaleAbs(image, beta=amount)
|
| 9 |
+
return img_bright
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def blur_image(image, amount):
|
| 13 |
+
blur_img = cv2.GaussianBlur(image, (11, 11), amount)
|
| 14 |
+
return blur_img
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def enhance_details(img):
|
| 18 |
+
hdr = cv2.detailEnhance(img, sigma_s=12, sigma_r=0.15)
|
| 19 |
+
return hdr
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def main_loop():
|
| 23 |
+
st.title("OpenCV Demo App")
|
| 24 |
+
st.subheader("This app allows you to play with Image filters!")
|
| 25 |
+
st.text("We use OpenCV and Streamlit for this demo")
|
| 26 |
+
|
| 27 |
+
blur_rate = st.sidebar.slider("Blurring", min_value=0.5, max_value=3.5)
|
| 28 |
+
brightness_amount = st.sidebar.slider("Brightness", min_value=-50, max_value=50, value=0)
|
| 29 |
+
apply_enhancement_filter = st.sidebar.checkbox('Enhance Details')
|
| 30 |
+
|
| 31 |
+
image_file = st.file_uploader("Upload Your Image", type=['jpg', 'png', 'jpeg'])
|
| 32 |
+
if not image_file:
|
| 33 |
+
return None
|
| 34 |
+
|
| 35 |
+
original_image = Image.open(image_file)
|
| 36 |
+
original_image = np.array(original_image)
|
| 37 |
+
|
| 38 |
+
processed_image = blur_image(original_image, blur_rate)
|
| 39 |
+
processed_image = brighten_image(processed_image, brightness_amount)
|
| 40 |
+
|
| 41 |
+
if apply_enhancement_filter:
|
| 42 |
+
processed_image = enhance_details(processed_image)
|
| 43 |
+
|
| 44 |
+
st.text("Original Image vs Processed Image")
|
| 45 |
+
st.image([original_image, processed_image])
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if __name__ == '__main__':
|
| 49 |
+
main_loop()
|