Skip to content

Commit

Permalink
Simple streamlit app
Browse files Browse the repository at this point in the history
  • Loading branch information
Ockenfuss committed May 18, 2024
1 parent d564706 commit d1c7e2a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
45 changes: 45 additions & 0 deletions streamlit_app.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d1c7e2a

Please sign in to comment.