Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vortex optical flow example #6041

Merged
merged 3 commits into from
Oct 19, 2023
Merged

Add vortex optical flow example #6041

merged 3 commits into from
Oct 19, 2023

Conversation

jni
Copy link
Member

@jni jni commented Jul 6, 2023

Fixes/Closes

Add example of optical flow to the gallery, based on scikit-image.

Screenshot 2023-07-06 at 8 08 33 pm

Epilepsy warning: the movie has some bright/dark flashing.

Screen.Recording.2023-07-06.at.8.05.37.pm.mov

I can remove the reverse phi stuff if people think it's too annoying/dangerous. But it's cool, thought I'd pull up a flashback from my postdoc 馃槀

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #6041 (262e5a2) into main (72538e5) will decrease coverage by 0.07%.
Report is 1 commits behind head on main.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #6041      +/-   ##
==========================================
- Coverage   91.98%   91.92%   -0.07%     
==========================================
  Files         596      596              
  Lines       52638    52638              
==========================================
- Hits        48421    48389      -32     
- Misses       4217     4249      +32     

see 12 files with indirect coverage changes

@jni jni added this to the 0.5 milestone Jul 6, 2023
Copy link
Contributor

@kephale kephale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a useful example. The flashing during playback should be opt-in.

@jni
Copy link
Member Author

jni commented Jul 7, 2023

I was wondering how I would make it opt-in @kephale... Do I just add both the normal contrast frames and the concatenated frames and make the concatenated version invisible? I could even add only the reverse contrast frames with an offset. But I worry both those options will be confusing...

I could also get rid of it altogether... But it's fun to see, no? 馃槂

@kephale
Copy link
Contributor

kephale commented Jul 7, 2023

I could see something like this helping in the long term: #6045

An short-term alternative is to use a colormap for vortex_phi like twilight that wraps around the color values.

@kephale
Copy link
Contributor

kephale commented Jul 8, 2023

Ok, poked a little more and I'm leaning to:

import numpy as np
from skimage.data import vortex
from skimage.registration import optical_flow_ilk
from scipy.ndimage import zoom

import napari

#######################################################################
# First, we load the vortex image, and then we create an inverted
# "negative" image. For the illusion, we concatenate them end-to-end.

stretch_factor = 5

vortex_im = np.asarray(vortex())
vortex_im = zoom(vortex_im, (stretch_factor, 1, 1), order=1)
vortex_neg = np.max(vortex_im) - vortex_im
vortex_phi = np.concatenate((vortex_im, vortex_neg), axis=0)

The vector lines need tweaking to be visible, but it still has the cool visual effect with less strobing. However, I would still be pretty tempted to not show vortex_neg.

Screen.Recording.2023-07-08.at.8.27.18.AM.mov

@jni
Copy link
Member Author

jni commented Jul 9, 2023

@kephale

An short-term alternative is to use a colormap for vortex_phi like twilight that wraps around the color values.

Then you would lose the illusion which is the whole point of the thing! 馃槀 The effect only works when you invert the contrast of the whole image. The only way to make it less stroby is to use a different image that has ~50% white pixels. And I'm not 100% convinced it would work anyway. I'm happy to drop it, I just thought it was a cute application and wanted to write it down somewhere. 馃槂 I'll do the standard vortex here and save the reverse-phi for my (long neglected) napari-demos repo.

Also what on earth did you do to my vectors 馃槀

@kephale
Copy link
Contributor

kephale commented Jul 9, 2023

Screen.Recording.2023-07-09.at.8.49.08.AM.mov

This seems to keep a balance between maintaining the illusion and having a gentle transition.

Yeah, vectors are super borked right now.

[edit: code here https://gist.github.com/kephale/8707eb105fc8c52168c1db16ac836580]

@jni
Copy link
Member Author

jni commented Oct 16, 2023

@kephale @napari/core-devs I've removed the reverse-phi illusion because (a) it was a bit controversial and (b) anyway it made the example more complicated than it needed to be.

The reverse-phi demo lives on at https://github.com/jni/napari-demos/blob/main/vortex.py

Since @kephale already approved this and it doesn't affect the main code in any way, I'm going to add the "ready-to-merge" label.

@jni jni added the ready to merge Last chance for comments! Will be merged in ~24h label Oct 16, 2023
@Czaki
Copy link
Collaborator

Czaki commented Oct 16, 2023

@jni could you fix milestone?

@jni jni modified the milestones: 0.5, 0.5.0 Oct 17, 2023
@Carreau
Copy link
Contributor

Carreau commented Oct 19, 2023

This got the "Ready-to-merge" label 2 days ago and got no objections. Merging to move the queue forward.

Thanks.

@Carreau Carreau merged commit 0bf6801 into napari:main Oct 19, 2023
32 checks passed
@jni jni deleted the vortex-example branch October 20, 2023 06:36
@Carreau Carreau removed the ready to merge Last chance for comments! Will be merged in ~24h label Oct 20, 2023
kne42 added a commit to kne42/napari that referenced this pull request Oct 25, 2023
* main: (59 commits)
  Fix permission for JasonEtco/create-an-issue@v2 action (napari#6370)
  Ensure the conda bundle workflows have the appropriate permissions (napari#6379)
  Exclude the loaded property when linking two layers (napari#6377)
  Automatic add `maintenance` label to upgrade dependecies workflow (napari#6371)
  Pydantic 2 compatibility using `pydantic.v1` (napari#6358)
  Update `fsspec`, `imageio`, `magicgui`, `napari-console`, `npe2`, `pillow`, `tensorstore`, `xarray` (napari#6367)
  fix `TransformChain.__getitem__` signature (napari#6369)
  Fix some typing in napari._vispy (napari#6245)
  Fix typing in napari.utils.theme (napari#6247)
  Fix typing in napari.layers.base (napari#6028)
  Fix build wheel workflow file name (napari#6357)
  Fix upstream deprecation: change `np.alltrue` to `np.array_equiv` (napari#6347)
  Add codecov token to reduce propability of fail to upload from main branch (napari#6346)
  Disable ptrace protection to make pytest-pystack work (napari#6343)
  Update example scripts (magicgui with threads) (napari#6353)
  Update `dask`, `hypothesis`, `numpy`, `pillow`, `pretend`, `psutil`, `pyqt5`, `pyqt6`, `pyside6`, `superqt` (napari#6322)
  Add vortex optical flow example (napari#6041)
  Enable memory benchmarks for layers (napari#6295)
  Fix labeler configuration (napari#6344)
  Add 'raise' option back to `strict_qt` in `make_napari_viewer` (napari#6335)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants