sunwaee commited on
Commit
3e5cb6b
·
1 Parent(s): 35efb41

added default image and update app

Browse files
Files changed (2) hide show
  1. app.py +18 -19
  2. 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 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. '))
@@ -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
- # 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(1-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')
 
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