czitools.export_tools.display #
Image display helpers for the OME-Zarr export tools.
Vendored (with light edits) from czi_omezarr_utils.display in the omezarr_playground repository as part of czitools Stage 5.
Contents
compute_pyramid_scale_factors— size-aware multiscale scale factors (Y/X only)get_fieldimage— extract a scene from a 6D array as a multi-scale NgffImageget_display— per-channel display-range settings from CZI metadatacreate_channel_list— OMERO channel list used by both write backends
Functions:
-
compute_pyramid_levels–Compute the number of resolution levels based on the 2D plane size.
-
compute_pyramid_scale_factors–Build size-aware, Y/X-only downscale factors for
ngff_zarr.to_multiscales. -
create_channel_list–Build the OMERO channel list used by both write backends.
-
create_ngff_omero_channels–Build ngff-zarr
OmeroChannelobjects from CZI metadata. -
get_display–Extract display-range settings for a channel from CZI metadata.
-
get_fieldimage–Extract a field image from a 6D array as a multi-scale representation.
compute_pyramid_levels #
compute_pyramid_levels(
size_y: int,
size_x: int,
min_size: int = 512,
max_levels: int = 6,
) -> int
Compute the number of resolution levels based on the 2D plane size.
The pyramid keeps halving the XY plane until the largest XY dimension of the coarsest level is roughly <= min_size pixels (i.e. it fits in about one chunk/tile). Small planes therefore get few (or no) extra levels, avoiding wasted tiny levels, while large planes get enough levels for smooth zoomed-out viewing.
Parameters:
-
(size_y#int) –Height of the base-resolution plane in pixels.
-
(size_x#int) –Width of the base-resolution plane in pixels.
-
(min_size#int, default:512) –Target maximum XY size of the coarsest level. Defaults to 512.
-
(max_levels#int, default:6) –Hard cap on the number of levels. Defaults to 6.
Returns:
-
int(int) –Number of resolution levels (>= 1, where 1 means base only, no pyramid).
Source code in czitools/export_tools/display.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
compute_pyramid_scale_factors #
compute_pyramid_scale_factors(
size_y: int,
size_x: int,
min_size: int = 512,
max_levels: int = 6,
) -> list
Build size-aware, Y/X-only downscale factors for ngff_zarr.to_multiscales.
Returns cumulative factors [2, 4, 8, ...] applied to the Y and X axes only (Z is not downsampled). The number of factors is levels - 1 where levels comes from :func:compute_pyramid_levels. An empty list means "base only".
Parameters:
-
(size_y#int) –Height of the base-resolution plane in pixels.
-
(size_x#int) –Width of the base-resolution plane in pixels.
-
(min_size#int, default:512) –Target maximum XY size of the coarsest level. Defaults to 512.
-
(max_levels#int, default:6) –Hard cap on the number of levels. Defaults to 6.
Returns:
-
list(list) –A list of per-level dicts
{"z": 1, "y": 2**i, "x": 2**i}(Y/X only, Z factor fixed at 1 = no Z downsampling), or an empty list when no pyramid is warranted.
Source code in czitools/export_tools/display.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
create_channel_list #
create_channel_list(metadata: CziMetadata) -> list
Build the OMERO channel list used by both write backends.
Parameters:
-
(metadata#CziMetadata) –Metadata with
channelinfoandmaxvalue_list.
Returns:
-
list(list) –Channel dicts with keys
color,label,active,window.
Source code in czitools/export_tools/display.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
create_ngff_omero_channels #
create_ngff_omero_channels(metadata: CziMetadata) -> list
Build ngff-zarr OmeroChannel objects from CZI metadata.
These are attached to a multiscale image so that OME-NGFF readers (e.g. ngio / napari-ome-zarr-navigator) can resolve per-channel display settings. Without OMERO channel metadata, ngio's channels_meta is None and the navigator ROI loader fails with 'NoneType' object has no attribute 'channels'.
Parameters:
-
(metadata#CziMetadata) –Metadata with
channelinfoandmaxvalue_list.
Returns:
-
list(list) –A list of :class:
ngff_zarr.OmeroChannelobjects (empty if no channel metadata is available).
Source code in czitools/export_tools/display.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
get_display #
get_display(
metadata: CziMetadata, channel_index: int
) -> tuple[float, float, float]
Extract display-range settings for a channel from CZI metadata.
Parameters:
-
(metadata#CziMetadata) –Metadata with channel display settings.
-
(channel_index#int) –Zero-based channel index.
Returns:
-
tuple[float, float, float]–tuple[float, float, float]:
(lower, higher, maxvalue). Falls back to(0, maxvalue, maxvalue)when metadata is missing or corrupted.
Source code in czitools/export_tools/display.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
get_fieldimage #
get_fieldimage(
array6d: DataArray | ndarray | Array,
scene_index: int,
metadata: CziMetadata,
min_size: int = 512,
max_levels: int = 6,
) -> Multiscales
Extract a field image from a 6D array as a multi-scale representation.
The number of resolution levels is derived from the 2D (Y, X) plane size via :func:compute_pyramid_scale_factors (downsampling Y/X only, never Z), so small fields get few/no extra levels and large fields get enough for smooth zoomed-out viewing.
Parameters:
-
(array6d#Union[DataArray, ndarray, Array]) –6D array with dimensions
[scene, t, c, z, y, x]. -
(scene_index#int) –Index of the scene to extract.
-
(metadata#CziMetadata) –Metadata with scale information and filename.
-
(min_size#int, default:512) –Target maximum XY size of the coarsest level. Defaults to 512.
-
(max_levels#int, default:6) –Hard cap on the number of levels. Defaults to 6.
Returns:
-
Multiscales–nz.Multiscales: Multi-scale representation using Gaussian downsampling with size-aware, Y/X-only scale factors.
Source code in czitools/export_tools/display.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |