A Streamlit Component to compare images with a slider in Streamlit apps.
Project description
Streamlit Image Comparison Component
A simple Streamlit Component to compare images with a slider in Streamlit apps using Knightlab's JuxtaposeJS. It accepts images in any format and makes it possible to set all parameters of the JS component via Python. Live demo at Huggingface Spaces
Installation
- Install via pip:
pip install streamlit
pip install streamlit-image-comparison
Example
# Streamlit Image-Comparison Component Example
import streamlit as st
from streamlit_image_comparison import image_comparison
# set page config
st.set_page_config(page_title="Image-Comparison Example", layout="centered")
# render image-comparison
image_comparison(
img1="image1.jpg",
img2="image2.jpg",
)
Supported Image Formats
# image path
image = "image.jpg"
# image url
image = "https://some-url.com/image.jpg"
# pil image
from PIL import Image
image = Image.open("image.jpg")
# opencv image
import cv2
image = cv2.cvtColor(cv2.imread("image.jpg"), cv2.COLOR_BGR2RGB)
# render image-comparison
image_comparison(
img1=image,
img2=image,
)
Customization
image_comparison(
img1="image1.jpg",
img2="image2.jpg",
label1="text1",
label2="text1",
width=700,
starting_position=50,
show_labels=True,
make_responsive=True,
in_memory=True,
)
Improvements
What is the difference between this repo and robmarkcole's?
- This is a pypi installable package
- This does not require the images to be saved under
site-packages/streamlit/static/
- This accepts any type of image as input (doesn't have to be present in local)
- This can utilize all parameters of the JS component
- This has an additional dependency
sahi
References
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for streamlit-image-comparison-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3932875978151eb89b65a2da5ca293fc15da12a322632214d96ce0146d9154b4 |
|
MD5 | a7e400f5c3ce70644ac7cdc6398eea40 |
|
BLAKE2b-256 | 68bfc163952ff3ccca0672474ac96e95c2e5abee7af63b9e49c194145e68ed05 |
Close
Hashes for streamlit_image_comparison-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84bb4bc8c9e66fd7ab28fdcd76cf87f0f27941e7288160fb9832c9322bd1f085 |
|
MD5 | 6ae77dc6bc3ba1f0185519a1fc6c80c2 |
|
BLAKE2b-256 | 4beb8c1f2f32f9fb201197ae8882e084b455356222ed5d9ba0f19c789e7a549e |