forked from tttamaki/show_img_hist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (29 loc) · 1016 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
import pandas as pd
import streamlit as st
from skimage.io import imread
# download the image
img_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Mount_Fuji_from_Mount_Aino.jpg/640px-Mount_Fuji_from_Mount_Aino.jpg'
im = imread(img_url)
st.image(im, caption='image from wwwwwwwwwwwwwwwwwwwwwwwwww',
use_column_width=True)
# show histgram of all colors
hist_red, _ = np.histogram(im[:, :, 0], bins=64)
hist_green, _ = np.histogram(im[:, :, 1], bins=64)
hist_blue, _ = np.histogram(im[:, :, 2], bins=64)
hist = np.stack((hist_red, hist_green, hist_blue), axis=1)
df_hist = pd.DataFrame(hist, columns=['R', 'G', 'B'])
st.bar_chart(df_hist)
# choose one color
color = st.radio(
"choose R, G, or B",
('R', 'G', 'B'))
if color == 'R':
df_hist = pd.DataFrame(hist_red)
st.bar_chart(df_hist)
if color == 'G':
df_hist = pd.DataFrame(hist_green)
st.bar_chart(df_hist)
if color == 'B':
df_hist = pd.DataFrame(hist_blue)
st.bar_chart(df_hist)