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
A python script for extracting/removing exif data from images by @AbirHasan2005

Image-Exif A Python script for extracting exif metadata from images. How to use? Using this script you can extract exif data from image and save in .c

Abir Hasan 13 Dec 16, 2022
Blender addon - convert empty image reference to image plane

Reference to image plane Convert reference images to a textured image mesh plane. As if it was imported with import image as plane Use on drag'n'dropp

Samuel Bernou 6 Nov 25, 2022
Script For Importing Image sequences into scrap mechanic via blueprints

To use dowload and extract "video makes.zip" Python has to be installed https://www.python.org/ (may not work on version lower than 3.9) Has to be run

2 Oct 30, 2021
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
Simple program to easily view Euler parameters in 3D.

Simple program to easily view Euler parameters in 3D.

5 Aug 20, 2021
A python program to generate ANSI art from images and videos

ANSI Art Generator A python program that creates ASCII art (with true color support if enabled) from images and videos Dependencies The program runs u

Pratyush Kumar 12 Nov 08, 2022
Snowfall - helpful image handling utils - abstracts various file and opencv and pil features into result oriented functions

snowfall helpful image handling utils - abstracts various file and opencv and pil features into result oriented functions usage examples: from image_h

Less Wright 2 Jan 09, 2022
Hide sensitive information in images

Data-Preserved Script allowing to blur the most sensitive information on images. Prerequisites Before you begin, ensure you have met the following req

2 Dec 01, 2021
An python script to convert images to upscaled versions made out of one-colour emojis.

ABOUT This is an python script to convert png, jpg and gif(output isnt animated :( ) images to scaled versions made out of one-colour emojis. Please n

0 Oct 19, 2022
Simple Python image processing & automatization project for a simple web based game

What is this? Simple Python image processing & automatization project for a simple web based game Made using only Github Copilot (except the color and

SGeri 2 Aug 15, 2022
Deep Illuminator is a data augmentation tool designed for image relighting.

Deep Illuminator Deep Illuminator is a data augmentation tool designed for image relighting. It can be used to easily and efficiently genera

George Chogovadze 52 Nov 29, 2022
🛹 Turn an SVG into an STL for stencil creation purposes

svg2stl This repository provides a script which takes as input an SVG such as this one: It outputs an STL file like this one: You can also see an inte

Max Halford 3 Dec 29, 2021
3D Reconstruction Software

Meshroom is a free, open-source 3D Reconstruction Software based on the AliceVision Photogrammetric Computer Vision framework. Learn more details abou

AliceVision 8.7k Jan 02, 2023
Craft PNG files that appear completely different in Apple software

Ambiguous PNG Packer Craft PNG files that appear completely different in Apple software

David Buchanan 1k Dec 29, 2022
A collection of python scripts which help you programatically create PNGs or GIFs

A collection of python scripts which help you programatically create PNGs or GIFs and their Metadata in bulk with custom rarity rates, upload them to OpenSea & list them for sale.

Tom 30 Dec 24, 2022
Me cleaner - Tool for partial deblobbing of Intel ME/TXE firmware images

me_cleaner me_cleaner is a Python script able to modify an Intel ME firmware image with the final purpose of reducing its ability to interact with the

Nicola Corna 4.1k Jan 08, 2023
Computer art based on quadtrees.

Quads Computer art based on quadtrees. The program targets an input image. The input image is split into four quadrants. Each quadrant is assigned an

Michael Fogleman 1.1k Dec 23, 2022
Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors

NanoImgPro Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors NanoImgPro.py contains the main class

1 Mar 02, 2022
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
The ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Dec 30, 2022