Skip to content

High level widgets #31

Closed
Closed
@kushalkolar

Description

@kushalkolar

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy