Blend between multiple images using a cell magic in JupyterLab using compare_view.
This project was called jupyter-splitview before.
pip install jupyter_compare_view
import jupyter_compare_view
%%compare
from skimage import data
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
img = data.chelsea()
grayscale_img = rgb2gray(img)
plt.imshow(img)
plt.axis("off")
plt.show()
plt.imshow(grayscale_img, cmap="gray")
plt.axis("off")
plt.show()
Another example:
from jupyter_compare_view import compare
compare(img, grayscale_img, cmap="gray", start_mode="horizontal", start_slider_pos=0.73)
The split view widget is still responsive after closing and reopening the notebook without running the cell again.
(Might still change in future)
-
--config '{"start_mode": "horizontal"}'
will init the compare-view in horizontal slider mode. -
--config '{"circle_size": 30}'
the circle size is now 30 pixel in circle mode. -
--config '{"show_slider": false}'
will hide the slider bar. -
--config '{"start_slider_pos": 0.73}'
will set the slider start position to 73%.- Removed in 0.1.1:
--position 73%
will no longer the slider start position to 73%.
- Removed in 0.1.1:
-
--config '{"start_mode": "horizontal","start_slider_pos": 0.73}'
will both set the start mode to horizontal and set the slider position -
--height 220
will set the height to 220 pixel. -
When
--height
is not provided, the default height of the widget is 300 pixel. -
--height auto
will set the height by the value of the first image's resolution in vertical direction. -
The widget's width will always be adjusted automatically.
Formatting with black can be done this way:
pip install 'black[jupyter]'
black --python-cell-magics compare compare_view_magic.ipynb
jupyter_compare_view fully supports offline interactive HTML exports. The web library compare_view is inlined into the exported HTML document. Therefore, the export is viewable without an internet connection.
git clone --recurse https://github.com/Octoframes/jupyter_compare_view
(Note: In case that the repo was already cloned e.g. with the GitHub Desktop client, the GitHub submodule has to be loaded viagit submodule update --init --recursive
)poetry install
Note: The IPython extension autoreload
reloads modules before every cell execution. Very useful when debugging the %%capture
cell magic!
Just add these lines into the first jupyter cell.
%load_ext autoreload
%autoreload 2
import jupyter_compare_view
CHange to importlib #48
Remove setuptools dependency
- Remove python3.7 support #46
- fix jupyterlite example
- Support python 3.11
- Implemented
capture
to display the compare view frame without calling the cell magic. This is not an ipywidget as mentioned here. - Update version requirements #42
- BugFix: Remove black import that was added by accident.
%%compare
is now%%splity
.%%splity
is deprecated.- Update examples
- octoframes github actions setup
- Move the repo from kolibril13/jupyter-spitview to octoframes/jupyter_compare_view
- Rename all references
- Drop the github.com/NUKnightLab/juxtapose backend and replace it with github.com/Octoframes/compare_view.
- Implement horizontal slider
- Implement Round Mask
- Update dependencies
- Update JupyterLite version
- Fix: in JupyterLite, a figure has to be explicitly called by plt.show()
- Better installation workflow
- Fixing problem with cell id and notebook reloading
- Experimentally lowering the dependencies to
ipython = ">=6.0.0"
andipykernel = ">=5.0.0"
so that jupyterlite will work hopefully.
- Rewrite of the import of JavaScript and CSS to make it more robust when closing and opening the notebook
- First attempt to add a JupyterLite example.
Fix poetry workflow
- Ship the javascript directly with the package, so no internet connection is required
- use jinja2 to save HTML in separate file
- load stylesheet and javascript only once in the beginning, and not in every cell that contains the splitview widget.
- New
--height
parameter
- default slider position
- updated minimal example
- internal code restructuring and formatting
- Handle import in non jupyter context
- save images in base64 strings and don't load images to disk (increases package security).
- First release