Skip to content

Commit

Permalink
rename splity to compare
Browse files Browse the repository at this point in the history
  • Loading branch information
kolibril13 committed Jul 18, 2022
1 parent 42a3779 commit 07d0ddf
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 551 deletions.
46 changes: 10 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Jupyter compare_view

Blend between multiple images using a cell magic in JupyterLab using [compare_view](https://github.com/Octoframes/compare_view).
*This project was called jupyter-splitview before.*

[![JupyterLight](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://octoframes.github.io/jupyter_compare_view)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Octoframes/jupyter_compare_view/HEAD?labpath=example_notebook.ipynb)
[![PyPI version](https://badge.fury.io/py/jupyter_compare_view.svg)](https://badge.fury.io/py/jupyter_compare_view)
[![MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Octoframes/jupyter_compare_view/blob/main/LICENSE)

Blend between multiple images using a cell magic in JupyterLab using [compare_view](https://github.com/Octoframes/compare_view).
*This project was called jupyter-splitview before.*


## Installation
```py
pip install jupyter_compare_view
Expand All @@ -17,7 +18,7 @@ import jupyter_compare_view
```

```py
%%splity
%%compare
from skimage import data
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
Expand All @@ -36,11 +37,9 @@ ax2.imshow(grayscale_img, cmap="gray")

<img src="https://user-images.githubusercontent.com/44469195/175052654-c6c06908-746b-4bcb-819f-c81c0e8dd521.png" style="width: 300px;"/>

Note: The split view widget is still responsive after closing and reopening the notebook without running the cell again.

Another example:
```py
%%splity --position 73% --height auto
%%compare --position 73% --height auto

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -54,6 +53,7 @@ ax2.imshow(array2)
```
<img src="https://user-images.githubusercontent.com/44469195/173763087-e76be74b-57e4-4861-ae0a-6c307021b785.png" style="width: 300px;"/>

The split view widget is still responsive after closing and reopening the notebook without running the cell again.

## Notebook arguments
(Might still change in future)
Expand All @@ -72,7 +72,7 @@ ax2.imshow(array2)
## Notebook formatting
Formatting with black can be done this way:
1. `pip install 'black[jupyter]'`
2. `black --python-cell-magics splity compare_view_magic.ipynb`
2. `black --python-cell-magics compare compare_view_magic.ipynb`


## Developer Installation
Expand All @@ -83,30 +83,6 @@ Formatting with black can be done this way:

## Changelog

## Milestones / Wishlist

* implement tests, find out how to test a magic class

* Idea: Second option without using cell magic:
```python
from jupyter_compare_view import Splity # (does not yet exist)
my_splity = Splity(left_layer=img1, right_layer=img2)
display(my_splity)
```

* Make this work also in VSCode notebooks, [see this issue](https://github.com/NUKnightLab/juxtapose/issues/178).

* Some other nice views, like these:

Round Mask:
<img src="https://user-images.githubusercontent.com/44469195/175031002-0f94c143-0145-4254-88ec-a8e450faa6af.png" style="width: 300px;"/>

Double Round Mask, Second one with 50% opacity:
<img src="https://user-images.githubusercontent.com/44469195/175031014-81e78b3a-9e74-4d21-b516-2c5a0cc7f869.png" style="width: 300px;"/>

Gaussian Mask (no priority):
<img src="https://user-images.githubusercontent.com/44469195/175031027-ef5da1f8-9c32-454f-aa1a-40d10eb086d6.png" style="width: 300px;"/>

## 1.0.0 (work in progress)

* Rename `%%splity` to `%%compare`
Expand Down Expand Up @@ -166,6 +142,4 @@ Fix poetry workflow
* save images in base64 strings and don't load images to disk (increases package security).
## 0.0.1

* First release


* First release
4 changes: 2 additions & 2 deletions debugging_notebooks/bug_retina_display.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height auto\n",
"%%compare --height auto\n",
"from skimage import data\n",
"from skimage.color import rgb2gray\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -84,7 +84,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height auto \n",
"%%compare --height auto \n",
"fig, ax1 = plt.subplots()\n",
"ax1.axis(\"off\")\n",
"ax1.imshow(img)\n",
Expand Down
4 changes: 2 additions & 2 deletions debugging_notebooks/twitter_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height auto\n",
"%%compare --height auto\n",
"from skimage import data\n",
"from skimage.color import rgb2gray\n",
"import matplotlib.pyplot as plt\n",
Expand All @@ -41,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height auto\n",
"%%compare --height auto\n",
"\n",
"# imports + figure definition here\n",
"\n",
Expand Down
1,014 changes: 511 additions & 503 deletions example_notebook.ipynb

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions jupyter_compare_view/sw_cellmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
@magics_class
class CompareViewMagic(Magics):
@magic_arguments.magic_arguments()
@magic_arguments.argument(
@magic_arguments.argument( # TODO This is currently not used.
"--position",
"-p",
default="50%",
help=("The start position of the slider"),
help= """The start position of the slider. Currently not implemented, use `--config '{"start_slider_pos": 0.73}'` instead""",
)
@magic_arguments.argument(
"--height",
Expand All @@ -36,7 +36,7 @@ class CompareViewMagic(Magics):
),
)
@cell_magic
def splity(self, line, cell):
def compare(self, line, cell): # TODO: make a %%splity deprecated version
"""Saves the png image and creates the compare_view canvas"""

with capture_output(stdout=False, stderr=False, display=True) as result:
Expand All @@ -53,7 +53,7 @@ def splity(self, line, cell):
raise ValueError("There need to be at least two images for Jupyter compare_view to work.")

# get the parameters that configure the widget
args = magic_arguments.parse_argstring(CompareViewMagic.splity, line)
args = magic_arguments.parse_argstring(CompareViewMagic.compare, line)

height = args.height

Expand All @@ -71,5 +71,4 @@ def splity(self, line, cell):
height=height,
# as JSON object
config=args.config,
)

)
4 changes: 2 additions & 2 deletions jupyterlite_compare_view_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height auto\n",
"%%compare --height auto\n",
"\n",
"img = data.chelsea()\n",
"grayscale_img = rgb2gray(img)\n",
Expand All @@ -65,7 +65,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%splity --height 400 --config '{\"start_mode\": \"horizontal\"}'\n",
"%%compare --height 400 --config '{\"start_mode\": \"horizontal\"}'\n",
"import numpy as np\n",
"\n",
"array1 = np.fromfunction(lambda i, j: np.sin(j*0.1), (20, 30))\n",
Expand Down

0 comments on commit 07d0ddf

Please sign in to comment.