From a51bc4676de117046cc611998b080f58ddf7c1b4 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Fri, 15 Nov 2024 23:37:27 -0500 Subject: [PATCH] start video points example --- examples/image_widget/video_roi_points.py | 55 +++++++++++++++++++++++ fastplotlib/graphics/selectors/_linear.py | 8 ++++ 2 files changed, 63 insertions(+) create mode 100644 examples/image_widget/video_roi_points.py diff --git a/examples/image_widget/video_roi_points.py b/examples/image_widget/video_roi_points.py new file mode 100644 index 000000000..dc26436bb --- /dev/null +++ b/examples/image_widget/video_roi_points.py @@ -0,0 +1,55 @@ +""" +Image Widget Pixel Timeseries +============================= + +Use an ImageWidget to view a grayscale video and click on pixels to show their values +over time (timeseries) +""" + +# test_example = true +# sphinx_gallery_pygfx_docs = 'animate 6s 20fps' + +import numpy as np +import fastplotlib as fpl +import imageio.v3 as iio + + +# download and open video file +print("download and reading video file") +url = "https://caiman.flatironinstitute.org/~neuro/caiman_downloadables/demoMovieJ.tif" +url = "/home/kushal/caiman_data/example_movies/demoMovieJ.tif" +video = iio.imread(url) + +iw = fpl.ImageWidget( + video, + cmap="viridis", + figure_kwargs={"size": (700, 600)} +) +iw.show() + +fig = fpl.Figure(size=(700, 400)) + +# add an initial point +row_ix, col_ix = 29, 65 +timeseries = fig[0, 0].add_line(video[:, row_ix, col_ix], thickness=1.0) +point = iw.figure[0, 0].add_scatter(np.column_stack([col_ix, row_ix]), sizes=10, alpha=0.7, colors="magenta") + +time_selector = timeseries.add_linear_selector() + + +@time_selector.add_event_handler("selection") +def set_time_from_selector(ev): + iw.current_index = {"t": ev.get_selected_index()} + + +@iw.managed_graphics[0].add_event_handler("double_click") +def update_pixel(ev): + col, row = ev.pick_info["index"] + + point.data[0, :2] = [col, row] + timeseries.data[:, 1] = video[:, row, col] + fig[0, 0].auto_scale(maintain_aspect=False) + + +fig.show(maintain_aspect=False) +fpl.run() diff --git a/fastplotlib/graphics/selectors/_linear.py b/fastplotlib/graphics/selectors/_linear.py index dfe7aadab..85a7e4c1f 100644 --- a/fastplotlib/graphics/selectors/_linear.py +++ b/fastplotlib/graphics/selectors/_linear.py @@ -47,6 +47,14 @@ def limits(self, values: tuple[float, float]): ) # if values are close to zero things get weird so round them self.selection._limits = self._limits + @property + def end_points(self) -> tuple[float, float]: + pass + + @end_points.setter + def end_points(self, points: tuple[float, float]): + pass + # TODO: make `selection` arg in graphics data space not world space def __init__( self, 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