Skip to content

add ignore_dims arg to subsample_array #797

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 2 commits into from
Apr 13, 2025
Merged
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion fastplotlib/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ def parse_cmap_values(
return colors


def subsample_array(arr: np.ndarray, max_size: int = 1e6):
def subsample_array(
arr: np.ndarray, max_size: int = 1e6, ignore_dims: Sequence[int] | None = None
):
"""
Subsamples an input array while preserving its relative dimensional proportions.

Expand Down Expand Up @@ -444,6 +446,10 @@ def subsample_array(arr: np.ndarray, max_size: int = 1e6):
max_size: int, default 1e6
maximum number of elements in subsampled array

ignore_dims: Sequence[int], optional
List of dimension indices to exclude from subsampling (i.e. retain full resolution).
For example, `ignore_dims=[0]` will avoid subsampling along the first axis.

Returns
-------
np.ndarray
Expand All @@ -462,4 +468,12 @@ def subsample_array(arr: np.ndarray, max_size: int = 1e6):
slices = tuple(
slice(None, None, int(s)) for s in np.floor(arr.shape / ns).astype(int)
)

# ignore dims e.g. RGB, which we don't want to downsample
if ignore_dims is not None:
for dim in ignore_dims:
slices[dim] = slice(None)

slices = tuple(slices)

return np.asarray(arr[slices])
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