Closed kolibril13 closed 9 months ago
huh - interesting! Thanks for the report - maybe @katherine-hutchings would like to take a look at this
One more note on this: the error only comes when gamma is decreasing. An increasing gamma does not throw any error:
from napari_animation import Animation
from napari_animation.easing import Easing
img = viewer.layers[0]
animation = Animation(viewer)
viewer.camera.zoom = 0.5
img.gamma = 0.2
animation.capture_keyframe(steps=30)
viewer.camera.zoom = 1.4
animation.capture_keyframe(steps=60, ease=Easing.QUADRATIC)
img.gamma = 1
animation.capture_keyframe(steps=30, ease=Easing.QUADRATIC)
# img.gamma = 0.9 # <-- only this would cause an error because gamma is decreaing
animation.capture_keyframe(steps=30, ease=Easing.QUADRATIC)
I can reproduce this, will poke around. Would be nice to get this fixed for sure.
The traceback above is truncated, not sure why. Here's the full:
Interestingly, checking the viewer_state
of key_frames
returns correct values, so I assume the interpolation is doing something wonky for decreasing values of gamma.
Hmm, I think I'm on to something:
Here's a trimmed viewer.layers[-1]._get_state()
:
{'name': 'astronaut',
'metadata': {},
'scale': [1.0, 1.0],
'translate': [0.0, 0.0],
'rotate': [[1.0, 0.0], [0.0, 1.0]],
'shear': [0.0],
'affine': array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]),
'opacity': 1.0,
'blending': 'translucent_no_depth',
'visible': True,
'experimental_clipping_planes': [],
'rgb': True,
'multiscale': False,
'colormap': 'gray',
'contrast_limits': [0, 255],
'interpolation2d': 'nearest',
'interpolation3d': 'linear',
'rendering': 'mip',
'depiction': 'volume',
'plane': {'normal': (1.0, 0.0, 0.0),
'position': (0.0, 0.0, 0.0),
'thickness': 1.0},
'iso_threshold': 127.5,
'attenuation': 0.05,
'gamma': 1,
gamma is 1
which will return type int
and will trigger wrong interpolation here:
https://github.com/napari/napari-animation/blob/969fefb5f442d7f6e1ba9ca7ae287a67f55c5c6d/napari_animation/interpolation/base_interpolation.py#L70-L88
So I think the issue lies in napari codebase, but as a temporary fix you can use
viewer.layers[-1].gamma = 1.0
(or whatever layer) to force the initial gamma to be a float for proper interpolation.
I ran into an error when changing the gamma value during an animation: "ValueError: gamma must be > 0" But the value of gamma only changes from 1 to 0.4, so it should never have a negative value. Minimal example to reproduce:
Whole message: