Spaces:
Runtime error
Runtime error
Initial commit
Browse files- .gitignore +1 -0
- README.md +1 -1
- app.py +56 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🔥
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
|
|
|
| 1 |
---
|
| 2 |
+
title: High Pass Filter for Images
|
| 3 |
emoji: 🔥
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
|
| 3 |
+
PROJECT: GaussianHighPassFilter
|
| 4 |
+
FILENAME: app.py
|
| 5 |
+
AUTHOR: David NAISSE
|
| 6 |
+
DATE: August 22, 2022
|
| 7 |
+
|
| 8 |
+
DESCRIPTION: App script.
|
| 9 |
+
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import streamlit as st
|
| 14 |
+
from PIL import Image
|
| 15 |
+
from scipy import ndimage
|
| 16 |
+
|
| 17 |
+
# Page config
|
| 18 |
+
st.set_page_config(layout="centered")
|
| 19 |
+
st.title("High Pass Filter for Images")
|
| 20 |
+
st.write('High pass filter applied to images. ')
|
| 21 |
+
|
| 22 |
+
left, right = st.columns([3, 2])
|
| 23 |
+
|
| 24 |
+
# Uploader
|
| 25 |
+
img_or_video = left.file_uploader("Upload an image or video: ", type=['.jpg', '.png', '.jpeg'])
|
| 26 |
+
|
| 27 |
+
# Display example selection
|
| 28 |
+
size = int(right.number_input('Filter size (ex: 3x3): ', min_value=3, max_value=500, value=3, help='Filter size. '))
|
| 29 |
+
|
| 30 |
+
# Init. empty texts
|
| 31 |
+
filter_text = right.empty()
|
| 32 |
+
size_text = right.empty()
|
| 33 |
+
|
| 34 |
+
# When a file is uploaded
|
| 35 |
+
if img_or_video:
|
| 36 |
+
original = Image.open(img_or_video)
|
| 37 |
+
image = np.array(original)
|
| 38 |
+
gray = np.array(original.convert('L'))
|
| 39 |
+
|
| 40 |
+
# Apply high pass
|
| 41 |
+
lowpass = ndimage.gaussian_filter(gray, size)
|
| 42 |
+
gauss_highpass = gray - lowpass
|
| 43 |
+
|
| 44 |
+
# Display original
|
| 45 |
+
st.image(gauss_highpass, caption='High Pass')
|
| 46 |
+
|
| 47 |
+
# Update elements
|
| 48 |
+
filter_text.write(f'Using filter of size {size}x{size}. ')
|
| 49 |
+
size_text.write(f'Image size: {gauss_highpass.shape}')
|
| 50 |
+
|
| 51 |
+
# Split UI in 2
|
| 52 |
+
left2, right2 = st.columns([5, 5])
|
| 53 |
+
|
| 54 |
+
# Display img
|
| 55 |
+
left2.image(image, caption='Original')
|
| 56 |
+
right2.image(lowpass, caption='Low Pass')
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit==1.12.0
|
| 2 |
+
numpy==1.23.2
|
| 3 |
+
Pillow==9.2.0
|
| 4 |
+
scipy==1.9.0
|