Spaces:
Runtime error
Runtime error
added default image and update app
Browse files- app.py +18 -19
- resource/example.jpg +0 -0
app.py
CHANGED
@@ -22,7 +22,7 @@ st.write('High pass filter applied to images. ')
|
|
22 |
left, right = st.columns([3, 2])
|
23 |
|
24 |
# Uploader
|
25 |
-
img_or_video = left.file_uploader("Upload an image
|
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. '))
|
@@ -31,26 +31,25 @@ size = int(right.number_input('Filter size (ex: 3x3): ', min_value=3, max_value=
|
|
31 |
filter_text = right.empty()
|
32 |
size_text = right.empty()
|
33 |
|
34 |
-
#
|
35 |
-
if img_or_video
|
36 |
-
|
37 |
-
|
38 |
-
gray = np.array(original.convert('L'))
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
22 |
left, right = st.columns([3, 2])
|
23 |
|
24 |
# Uploader
|
25 |
+
img_or_video = left.file_uploader("Upload an image: ", 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. '))
|
|
|
31 |
filter_text = right.empty()
|
32 |
size_text = right.empty()
|
33 |
|
34 |
+
# Default image or uploaded one
|
35 |
+
original = Image.open("resource/example.jpg" if img_or_video is None else img_or_video)
|
36 |
+
image = np.array(original)
|
37 |
+
gray = np.array(original.convert('L'))
|
|
|
38 |
|
39 |
+
# Apply high pass
|
40 |
+
lowpass = ndimage.gaussian_filter(gray, size)
|
41 |
+
gauss_highpass = gray - lowpass
|
42 |
|
43 |
+
# Display original
|
44 |
+
st.image(1-gauss_highpass, caption='High Pass')
|
45 |
|
46 |
+
# Update elements
|
47 |
+
filter_text.write(f'Using filter of size {size}x{size}. ')
|
48 |
+
size_text.write(f'Image size: {gauss_highpass.shape}')
|
49 |
|
50 |
+
# Split UI in 2
|
51 |
+
left2, right2 = st.columns([5, 5])
|
52 |
|
53 |
+
# Display img
|
54 |
+
left2.image(image, caption='Original')
|
55 |
+
right2.image(lowpass, caption='Low Pass')
|
resource/example.jpg
ADDED
![]() |