Skip to content

Instantly share code, notes, and snippets.

@ash2shukla
Created October 15, 2020 11:10
Show Gist options
  • Save ash2shukla/f763d205a8e82a4fdd0d6534f3dae048 to your computer and use it in GitHub Desktop.
Save ash2shukla/f763d205a8e82a4fdd0d6534f3dae048 to your computer and use it in GitHub Desktop.
Image Color Change
import streamlit as st
import io
from PIL import Image
original, modified = st.beta_columns(2)
image_box = original.empty()
filter_type = original.empty()
image = original.file_uploader("Upload Image")
BLUE_FILTER = ( 0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 1, 0)
GREEN_FILTER = ( 0, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 0)
RED_FILTER = ( 0, 0, 1, 0,
0, 0, 0, 0,
0, 0, 0, 0)
filter_map = {
"green": GREEN_FILTER,
"blue": BLUE_FILTER,
"red": RED_FILTER
}
if image:
img_buffer = io.BytesIO(image.getbuffer())
filter_type = filter_type.selectbox("Select Filter", ["green", "blue", "red"])
image_box.image(img_buffer, use_column_width=True)
img = Image.open(img_buffer).convert("RGB").convert("RGB", matrix=filter_map[filter_type])
modified.image(img, use_column_width=True)
else:
modified.image("https://developers.google.com/maps/documentation/streetview/images/error-image-generic.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment