Image comparison slider component for Streamlit

Overview

Streamlit Image Comparison Component

pypi version HuggingFace Spaces

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

Comments
  • predict is not working

    predict is not working

    It gives an error when I upload a photo and run it.

    Error Mesage:

    File "/home/user/.local/lib/python3.8/site-packages/streamlit/script_runner.py", line 354, in _run_script
        exec(code, module.__dict__)
    File "/home/user/app/app.py", line 208, in <module>
        output_1, output_2 = sahi_mmdet_inference(
    File "/home/user/app/utils.py", line 24, in sahi_mmdet_inference
        prediction_result_1 = sahi.predict.get_prediction(
    File "/home/user/.local/lib/python3.8/site-packages/sahi/predict.py", line 80, in get_prediction
        detection_model.perform_inference(np.ascontiguousarray(image_as_pil), image_size=image_size)
    File "/home/user/.local/lib/python3.8/site-packages/sahi/model.py", line 235, in perform_inference
        prediction_result = inference_detector(self.model, image)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/apis/inference.py", line 129, in inference_detector
        data = test_pipeline(data)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/datasets/pipelines/compose.py", line 41, in __call__
        data = t(data)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/datasets/pipelines/test_time_aug.py", line 107, in __call__
        data = self.transforms(_results)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/datasets/pipelines/compose.py", line 41, in __call__
        data = t(data)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/datasets/pipelines/transforms.py", line 656, in __call__
        self._pad_img(results)
    File "/home/user/.local/lib/python3.8/site-packages/mmdet/datasets/pipelines/transforms.py", line 622, in _pad_img
        padded_img = mmcv.impad(
    File "/home/user/.local/lib/python3.8/site-packages/mmcv/image/geometric.py", line 486, in impad
        assert len(pad_val) == img.shape[-1]
    
    opened by kadirnar 4
  • Removed margin from body element

    Removed margin from body element

    I have removed the margin from the body element with an extra style tag.

    image

    It might be worth noting that the default width (if the container size is not set to max) is 704 pixels. I also changed the default width to this.

    This allows the component to render nicely in the container in which it is created. :)

    opened by darkeclipz 1
  • Suggestion

    Suggestion

    This is a nice improvement, I suggest an addition in the comparison to my repo is to mention that there are additional dependencies in this version via sahi

    opened by robmarkcole 1
  • Using plots/images directly within Streamlit app without saving them

    Using plots/images directly within Streamlit app without saving them

    Hi there,

    Excellent Streamlit component, thanks for making it available!

    I wanted to ask if there is a way of parsing directly figures from plot onto it, instead of using saved image files?

    Example usage: Having fig1, fig2 created in matplotlib within Streamlit app and then using fig1 and fig2 directly in streamlit-image-comparison?

    Cheers, Robert

    help wanted 
    opened by rdzudzar 3
  • Inherit scale and location properties

    Inherit scale and location properties

    Hey all, what a great visualization tool!

    I might have a suggestoin that would make it even nicer to use.

    The main thing that would improve the usability a lot would be 'automatic scaling'. Even with the use of different screen sizes, the image-comparison result will always have a fixed size (pixel based) If you're only working on one device, you can tailor it for this. Unfortunately this won't be the case for many uses though. Therefore I believe that it would be beneficial to make the size scalable, just as all 'default' streamlit plotting options, like st.image. At this moment, some funny things can happen when using columns, or calling other streamlit objects after calling image_comparison().

    As a simplified example of what I mean, I added a screenshot of how my app looks, after I've called the following code:

    # set columns
    cols = st.columns(2)
    
    # define which image you want to see
    image_sel = cols[0].selectbox('Select the image you want to see.', image_name_list)
    
    # next I want to see this image using image_comparison
    image_comparison(image_1, image_2)
    
    # beneath the image I want to call an expander to modify some settings of this image
    modifier = cols[0].form('Modify this image')
    with modifier:
        threshold = st.slider(f"Select a new threshold. The default threshold = 19.", 1, 100, 19, 1)
        if st.form_submit_button('Re-analyze image.'):
            image_dict = analyze_image(image_dict) # image_dict contains all metadata and images for this selected image, and is updated by using the different threshold
    
    cols[1].plotly_chart(figure)
    

    As you can see, the order of the calls does not correspond to the location of the image_comparison result. Screenshot from 2022-04-14 16-44-52

    In the end, I would imagine calling image_comparison like: st.image_comparison, or col1.image_comparison

    I don't know how much work this is though. Let me know what you think, and again, thank you for the nice tool!

    Cheer, Dirk

    help wanted 
    opened by DirkRemmers 1
Releases(0.0.3)
  • 0.0.3(Dec 12, 2022)

    What's Changed

    • Removed margin from body element by @darkeclipz in https://github.com/fcakyon/streamlit-image-comparison/pull/12

    New Contributors

    • @darkeclipz made their first contribution in https://github.com/fcakyon/streamlit-image-comparison/pull/12

    Full Changelog: https://github.com/fcakyon/streamlit-image-comparison/compare/0.0.2...0.0.3

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Dec 1, 2021)

    What's Changed

    • update sahi version by @fcakyon in https://github.com/fcakyon/streamlit-image-comparison/pull/4
    • update readme by @fcakyon in https://github.com/fcakyon/streamlit-image-comparison/pull/3

    Full Changelog: https://github.com/fcakyon/streamlit-image-comparison/compare/0.0.1...0.0.2

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Nov 25, 2021)

    initial release (v0.0.1)

    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. Try it on ...

    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,
    )
    
    Source code(tar.gz)
    Source code(zip)
Owner
fatih
senior machine learning engineer    phd candidate             metu & bilkent alum.
fatih
OctoPrint is the snappy web interface for your 3D printer!

OctoPrint OctoPrint provides a snappy web interface for controlling consumer 3D printers. It is Free Software and released under the GNU Affero Genera

OctoPrint 7.1k Jan 03, 2023
Goddard Image Analysis and Navigation Tool

Copyright 2021 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. No copyright is clai

NASA 12 Dec 23, 2022
image-processing exercises.

image_processing Assignment 21 Checkered Board Create a chess table using numpy and opencv. view: Color Correction Reverse black and white colors with

Benyamin Zojaji 25 Dec 15, 2022
Convert photos to paintings with python

Convert-photos-to-paintings Before the changes After the changes Before the changes After the changes This code is written in the Python programming l

Amir Hussein Sharifnezhad 3 May 31, 2022
This projects aim is to simulate flowers(Gerbera Daisy) phyllotaxis.

phyllotaxis This projects aim is to simulate flowers(Gerbera Daisy) phyllotaxis. Take a look at the arrangement of this flower's seeds, this project's

amirsalar 3 Dec 10, 2021
Music Thumbnail Maker

Music Thumbnail Installing pip install TMFrame

krypton 4 Jan 28, 2022
A SIXEL encoder/decoder implementation derived from kmiya's sixel

libsixel What is this? This package provides encoder/decoder implementation for DEC SIXEL graphics, and some converter programs. (https://youtu.be/0Sa

Hayaki Saito 2k Jan 09, 2023
Extract the ISO 11146 beam size from an image file

laserbeamsize Simple and fast calculation of beam sizes from a single monochrome image based on the ISO 11146 method of variances. Some effort has bee

Scott Prahl 21 Jan 06, 2023
Python pygame project that turns your images to matrix rain

Matrix-Rain-An-Image This project implements the classic Matrix digital rain effect in python with pygame to build up an image provided with multiple

7 Dec 11, 2022
A little Python tool to convert a TrueType (ttf/otf) font into a PNG for use in demos.

font2png A little Python tool to convert a TrueType (ttf/otf) font into a PNG for use in demos. To use from command line it expects python3 to be at /

Rich Elmes 3 Dec 22, 2021
Raven is a tool written in Python3 allowing you to generate an unique image with some text.

🐦 Raven is a tool written in Python3 allowing you to generate an unique image with some text. It does it by searching the text on Google, do

Billy 39 Dec 20, 2022
kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns

kikuchipy is an open-source Python library for processing and analysis of electron backscatter diffraction (EBSD) patterns. The library builds on the

pyxem 53 Dec 29, 2022
Fast Image Retrieval (FIRe) is an open source image retrieval project

Fast Image Retrieval (FIRe) is an open source image retrieval project release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This project implements most of the major bi

CISiP Lab 39 Nov 25, 2022
An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters.

Ascii Artist An ascii art generator that's actually good. Does edge detection and selects the most appropriate characters. Installing Installing with

18 Jan 03, 2023
HCaptcha solver using requests and an image recognition package!

HCaptcha solver using requests and an image recognition package! Report Bug · Request Feature Features Image recognition Requests base

dropout 6 Oct 22, 2021
An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C. Overview Her

Sy Brand 228 Dec 17, 2022
Image2scan - a python program that can be applied on an image in order to get a scan of it back

image2scan Purpose image2scan is a python program that can be applied on an image in order to get a scan of it back. For this purpose, it searches for

Kushal Shingote 2 Feb 13, 2022
ScreenTeX is a tool that grabs all text when taking a screenshot rather than getting an image.

The ScreenTeX project By: Seanpm2001 / ScreenTeX, Et; Al. Top README.md Read this article in a different language 🌐 List of languages Sorted by: A-Z

Sean P. Myrick V19.1.7.2 3 Oct 25, 2022
Script that organizes the Google Takeout archive into one big chronological folder

Script that organizes the Google Takeout archive into one big chronological folder

Mateusz Soszyński 1.6k Jan 09, 2023
QR-code Generator with a basic GUI.

Qr_generator_python Qr code generator with a basic GUI. ❔ About the QR-Code-Generator This project Generates QR codes to sites, e-mails and plain text

Tecixck 2 Oct 11, 2021