Skip to content

ImageWidget #51

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Dec 11, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1fea4aa
started implementation of ImageWidget, nothing is tested yet
kushalkolar Dec 2, 2022
1bc65a0
basic stuff finished for single plot with a slider, need to test
kushalkolar Dec 2, 2022
6592cc3
basic image widget works
kushalkolar Dec 2, 2022
658f298
docs
kushalkolar Dec 2, 2022
5cc91ae
splitting imagewidget into two classes
kushalkolar Dec 4, 2022
7a6a136
split ImageWidget into ImageWidgetSingle and later ImageWidgetGrid
kushalkolar Dec 4, 2022
7cce91f
combined single and grid ImageWidget into single class
kushalkolar Dec 4, 2022
56a9b1c
simple and grid image widget works, tested with simple args, need to …
kushalkolar Dec 4, 2022
79f4452
catch another user error
kushalkolar Dec 4, 2022
e4f6b12
fix type annotation
kushalkolar Dec 4, 2022
5028ce7
docstrings, started slice_avg implementation
kushalkolar Dec 4, 2022
5ef32eb
slice averaging on single and multiple dimensions works perfectly
kushalkolar Dec 5, 2022
eca6599
is_array() checks for and attr, better error messages
kushalkolar Dec 8, 2022
0e3cf16
rename axis -> dims
kushalkolar Dec 10, 2022
570c076
make most imagewidget methods private, most attributes as read-only p…
kushalkolar Dec 10, 2022
4764b84
quick_min_max() returns pre-computed min max if int or float, imagewi…
kushalkolar Dec 10, 2022
afc0378
vmin vmax for gridplot
kushalkolar Dec 10, 2022
fc3365b
Merge branch 'master' into high-level-widgets
kushalkolar Dec 11, 2022
b1e922c
update Image -> ImageGraphic
kushalkolar Dec 11, 2022
e6c5d3a
refactor, window_funcs now works very well, slow with multiple dims b…
kushalkolar Dec 11, 2022
64faffd
vminmax works, also added names for subplots, everything works
kushalkolar Dec 11, 2022
8fc63b3
proper-ish image widget example
kushalkolar Dec 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docstrings, started slice_avg implementation
  • Loading branch information
kushalkolar committed Dec 4, 2022
commit 5028ce799e63d30bc18774d27b4b407be5701929
70 changes: 62 additions & 8 deletions fastplotlib/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,60 @@ def is_arraylike(obj) -> bool:


class ImageWidget:
"""
A high level for displaying n-dimensional image data in conjunction with automatically generated sliders for
navigating through 1-2 selected dimensions within the image data.

Can display a single n-dimensional image array or a grid of n-dimensional images.
"""
def __init__(
self,
data: np.ndarray,
data: Union[np.ndarray, List[np.ndarray]],
axes_order: Union[str, Dict[np.ndarray, str]] = None,
slider_axes: Union[str, int, List[Union[str, int]]] = None,
slice_avg: Dict[Union[int, str], int] = None,
slice_avg: Union[int, Dict[Union[int, str], int]] = None,
frame_apply: Union[callable, Dict[Union[int, str], callable]] = None,
grid_shape: Tuple[int, int] = None,
**kwargs
):
"""
A high level for displaying n-dimensional image data in conjunction with automatically generated sliders for
navigating through 1-2 selected dimensions within the image data.

Can display a single n-dimensional image array or a grid of n-dimensional images.

Default axes orders:

======= ==========
n_dims axes order
======= ==========
2 "xy"
3 "txy"
4 "tzxy"
======= ==========

Parameters
----------
data: Union[np.ndarray, List[np.ndarray]
array-like or a list of array-like

axes_order: Optional[Union[str, Dict[np.ndarray, str]]]
| a single ``str`` if ``data`` is a single array or if List[data] all have the same axes order
| dict mapping of ``{array: axis_order}`` if specific arrays have a non-default axes order.

slider_axes: Optional[Union[str, int, List[Union[str, int]]]]
| The axes/dimensions for which to create a slider
| can be a single ``str`` such as "t", "z" etc. or a numerical ``int`` that indexes the desired dimension
| can also be a list of ``str`` or ``int`` if multiple sliders are desired for multiple dimensions

slice_avg: Dict[Union[int, str], int]
| average one or more dimensions using a given window
| dict mapping of ``{dimension: window_size}``
| dimension/axes can be specified using ``str`` such as "t", "z" etc. or ``int`` that indexes the dimension
| if window_size is not an odd number, adds 1
| use ``window_size = 0`` to disable averaging for a dimension, example: ``{"t": 5, "z": 0}``

frame_apply
grid_shape: Optional[Tuple[int, int]]
manually provide the shape for a gridplot, otherwise a square gridplot is approximated.

kwargs: Any
passed to fastplotlib.graphics.Image
"""
if isinstance(data, list):
# verify that it's a list of np.ndarray
if all([is_arraylike(d) for d in data]):
Expand Down Expand Up @@ -172,6 +210,18 @@ def __init__(
elif isinstance(slider_axes, list):
self.slider_axes: List[str] = list()

if slice_avg is not None:
if not isinstance(slice_avg, dict):
raise TypeError(
f"`slice_avg` must be a <dict> if multiple `slider_axes` are provided. You must specify the "
f"window for each dimension."
)
if not isinstance(frame_apply, dict):
raise TypeError(
f"`frame_apply` must be a <dict> if multiple `slider_axes` are provided. You must specify a "
f"function for each dimension."
)

for sax in slider_axes:
if isinstance(sax, int):
ao = np.array([v for v in self.axes_order])
Expand Down Expand Up @@ -208,6 +258,10 @@ def __init__(

if self.plot_type == "single":
self.plot: Plot = Plot()

if slice_avg is not None:
pass

frame = self.get_2d_slice(self.data[0], slice_indices=self.current_index)

self.image_graphics: List[Image] = [self.plot.image(data=frame, **kwargs)]
Expand Down
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