From d1c7e2a5d34c7596b0a7049a68da31c318dba311 Mon Sep 17 00:00:00 2001 From: Paul Ockenfuss <42680748+Ockenfuss@users.noreply.github.com> Date: Sat, 18 May 2024 18:43:10 +0200 Subject: [PATCH] Simple streamlit app --- pyproject.toml | 4 ++-- streamlit_app.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 streamlit_app.py diff --git a/pyproject.toml b/pyproject.toml index 4ce3de1..f3fa51a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "crazybin" version = "1.0.0" -description = "Much better than hexbins plots! Use any kind of tile to visualize data and pictures!" +description = "Much better than hexbin plots! Use any kind of tile to visualize data and pictures!" readme = "README.md" authors = [{ name = "Paul Ockenfuß", email = "paul.ockenfuss@physik.uni-muenchen.de" }] license = { file = "LICENSE" } @@ -26,7 +26,7 @@ dependencies = [ requires-python = ">=3.9" [project.optional-dependencies] -dev = ["check-manifest", "build", "twine"] +dev = ["check-manifest", "build", "twine", "streamlit"] [project.urls] Homepage = "https://github.com/Ockenfuss/crazybin" diff --git a/streamlit_app.py b/streamlit_app.py new file mode 100644 index 0000000..b3dc025 --- /dev/null +++ b/streamlit_app.py @@ -0,0 +1,45 @@ +import streamlit as st +import matplotlib.pyplot as plt +import math +from crazybin import imshow + +def main(): + st.title("Image Tesselation") + st.write("This app allows you to transform your images into a parquet of small tiles.") + st.write("Just upload and image and select the type of tile you want together with the resolution.") + + tile_descriptions = { + "Regular hexagon": "hex", + "Composition of a regular hexagon, triangles and squares": "hex_rhomb", + "Composition of three lizard shaped tiles inspired by M.C. Escher": "reptile", + "Composition of four frog shaped tiles inspired by M.C. Escher.": "frog", + "Irregular P3 penrose tiling, consisting of two rhombs with different angles.": "pen_rhomb", + } + tile_types={"hex": "regular", "hex_rhomb": "regular", "reptile": "regular", "frog": "regular", "pen_rhomb": "irregular"} + + file = st.file_uploader("Choose an image file", type=["png", "jpg", "jpeg"]) + selected_description = st.selectbox("Choose a tile type", list(tile_descriptions.keys())) + tile_key=tile_descriptions[selected_description] + slidermax=10 + resolution = st.slider("Choose the resolution", min_value=1, max_value=slidermax, value=5) + + if file is not None: + image=plt.imread(file)/255 + st.subheader("Original Image:") + st.image(image, use_column_width=True) + + if tile_types[tile_key]=="regular": + #go exponentially from 1 to 100 + resolution=math.ceil(100**((resolution-1)/(slidermax-1))) + + + st.subheader("Tesselated image:") + print(resolution) + print(tile_types[tile_key]) + fig, ax = plt.subplots() + imshow(image, tile=tile_key, ax=ax, gridsize=resolution) + ax.axis('off') + st.pyplot(fig) + +if __name__ == "__main__": + main() \ No newline at end of file