Closed
Description
Takes numpy array-like (such as pims
objects), choose axes to have sliders on, displays plot. Could also have gridplot where multiple numpy arrays are given and sliders are synced across plots.
something like:
from fastplotlib.widgets import ImageWidget
import cv2
import pims
a = pims.open("img.tiff") # array-like of shape [n_frames, x, y]
vid = pims.open("vid.avi") # array-like of shape [n_frames, x, y, rgb_channels]
# produces a slider for each axis passed to `slider_axes`
# additional kwargs are passed to `graphics.Image`, such as `cmap`
iw = ImageWidget(data=a, slider_axes=0, axis_order="txy", **kwargs)
# could also specify slider axis from one of the axis_order indicators
# this could be the default kwarg for slider_axes
iw = ImageWidget(data=a, slider_axes="t", axis_order="txy", **kwargs)
iw.show() # returns `VBox` of `ImageWidget` and `ipywidgets.IntSlider`
# multiple sliders
iw = ImageWidget(data=a, slider_axes=["t", "z"], axis_order="tzxy", **kwargs)
# pass a frame apply function that is applied to the frame array when `update_frame()` is called
to_gray = lambda rgb_frame: cv2.cvtColor(rgb_frame, cv2.COLOR_BGR2GRAY)
iw_vid = ImageWidget(data=b, slider_axes=0, frame_apply=to_gray)
# Same widget but with gridplot, pass list of array-like
iw_grid = ImageWidget(
data=[a, b],
slider_axes=0, # use 0th axis for a single slider for both arrays
frame_apply={b: to_gray}
)
iw_grid.show()
# if a.shape[0] != b.shape[0] it can print a warning and just not update `a` when it goes out of bounds for it, but continue updating `b`
# create multiple sliders for different dimensions
iw_grid_async = ImageWidget(
data=[a, b],
slider_axes=["t", "z"],
axes_order={a: "tzxy", b: "xyzt"},
slice_avg={"t": 10, "z": 1}, # window size for slice averaging along some axes
frame_apply={b: to_gray}
)
iw_grid_async.show()
Metadata
Metadata
Assignees
Labels
No labels