miblab-plot 0.0.10__tar.gz → 0.0.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {miblab_plot-0.0.10/src/miblab_plot.egg-info → miblab_plot-0.0.12}/PKG-INFO +1 -1
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/pyproject.toml +1 -1
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/image_3d.py +47 -10
- {miblab_plot-0.0.10 → miblab_plot-0.0.12/src/miblab_plot.egg-info}/PKG-INFO +1 -1
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/LICENSE +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/README.md +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/setup.cfg +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/__init__.py +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/gui.py +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/movie.py +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/mp4.py +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot/pvplot.py +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot.egg-info/SOURCES.txt +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot.egg-info/dependency_links.txt +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot.egg-info/requires.txt +0 -0
- {miblab_plot-0.0.10 → miblab_plot-0.0.12}/src/miblab_plot.egg-info/top_level.txt +0 -0
|
@@ -24,7 +24,7 @@ def db_mosaic(series_to_display, pngfile, title="Center slices"):
|
|
|
24
24
|
aspect_ratio = 16/9
|
|
25
25
|
nrows = int(np.ceil(np.sqrt(n_imgs / aspect_ratio)))
|
|
26
26
|
ncols = int(np.ceil(aspect_ratio * nrows))
|
|
27
|
-
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, gridspec_kw = {'wspace':0, 'hspace':0}, figsize=(ncols, nrows), dpi=300)
|
|
27
|
+
fig, ax = plt.subplots(nrows=nrows, ncols=ncols, squeeze=False, gridspec_kw = {'wspace':0, 'hspace':0}, figsize=(ncols, nrows), dpi=300)
|
|
28
28
|
|
|
29
29
|
i=0
|
|
30
30
|
for row in tqdm(ax, desc='Building png'):
|
|
@@ -211,18 +211,42 @@ def checkerboard(fixed: np.ndarray, coreg: np.ndarray, square_size: int) -> np.n
|
|
|
211
211
|
|
|
212
212
|
return checker
|
|
213
213
|
|
|
214
|
-
|
|
214
|
+
def _label_to_binary_masks(label_image, background_value=0):
|
|
215
|
+
"""
|
|
216
|
+
Converts a label image into a list of binary masks.
|
|
217
|
+
|
|
218
|
+
Parameters:
|
|
219
|
+
- label_image (np.ndarray): 2D array of labels.
|
|
220
|
+
- background_value (int): Value representing the background to ignore.
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
- dict: A dict of label: 2D binary mask pairs.
|
|
224
|
+
"""
|
|
225
|
+
# Find all unique labels excluding the background
|
|
226
|
+
unique_labels = np.unique(label_image)
|
|
227
|
+
unique_labels = unique_labels[unique_labels != background_value]
|
|
228
|
+
|
|
229
|
+
masks = {}
|
|
230
|
+
for label in unique_labels:
|
|
231
|
+
# Create a binary mask for the current label
|
|
232
|
+
mask = (label_image == label).astype(bool)
|
|
233
|
+
masks[label] = mask
|
|
234
|
+
|
|
235
|
+
return masks
|
|
215
236
|
|
|
216
237
|
def mosaic_overlay(
|
|
217
|
-
img,
|
|
218
|
-
rois,
|
|
219
|
-
file,
|
|
238
|
+
img: np.ndarray, # background greyscale image
|
|
239
|
+
rois: dict | np.ndarray, # Dictionary with masks or label image
|
|
240
|
+
file: str=None,
|
|
220
241
|
colormap='tab20',
|
|
221
242
|
aspect_ratio=1.8,
|
|
222
243
|
margin=None,
|
|
223
244
|
vmin=None,
|
|
224
245
|
vmax=None,
|
|
225
246
|
opacity=0.6,
|
|
247
|
+
colors=None,
|
|
248
|
+
show=False,
|
|
249
|
+
verbose=1,
|
|
226
250
|
):
|
|
227
251
|
|
|
228
252
|
# Set defaults color window
|
|
@@ -231,8 +255,15 @@ def mosaic_overlay(
|
|
|
231
255
|
if vmax is None:
|
|
232
256
|
vmax=np.mean(img) + 2 * np.std(img)
|
|
233
257
|
|
|
258
|
+
# Convert label image to dictionary of masks
|
|
259
|
+
if not isinstance(rois, dict):
|
|
260
|
+
rois = _label_to_binary_masks(rois, background_value=0)
|
|
261
|
+
if rois == {}:
|
|
262
|
+
raise ValueError("Empty label image: nothing to overlay here..")
|
|
263
|
+
|
|
234
264
|
# Define RGBA colors (R, G, B, Alpha) — alpha controls transparency
|
|
235
|
-
colors
|
|
265
|
+
if colors is None:
|
|
266
|
+
colors = get_distinct_colors(rois, colormap=colormap, opacity=opacity)
|
|
236
267
|
|
|
237
268
|
# Get all masks as boolean arrays
|
|
238
269
|
masks = [m.astype(bool) for m in rois.values()]
|
|
@@ -242,7 +273,7 @@ def mosaic_overlay(
|
|
|
242
273
|
for i in range(1, len(masks)):
|
|
243
274
|
all_masks = np.logical_or(all_masks, masks[i])
|
|
244
275
|
if np.sum(all_masks)==0:
|
|
245
|
-
raise ValueError('Empty masks')
|
|
276
|
+
raise ValueError('Empty masks: nothing to overlay here.')
|
|
246
277
|
|
|
247
278
|
# Find corners of cropped mask
|
|
248
279
|
for x0 in range(all_masks.shape[0]):
|
|
@@ -301,7 +332,7 @@ def mosaic_overlay(
|
|
|
301
332
|
|
|
302
333
|
# Build figure
|
|
303
334
|
i = 0
|
|
304
|
-
for row in tqdm(ax, desc='Building png'):
|
|
335
|
+
for row in tqdm(ax, desc='Building png', disable=verbose==0):
|
|
305
336
|
for col in row:
|
|
306
337
|
|
|
307
338
|
col.set_xticklabels([])
|
|
@@ -330,8 +361,14 @@ def mosaic_overlay(
|
|
|
330
361
|
i += 1
|
|
331
362
|
|
|
332
363
|
# fig.suptitle('Mask overlay', fontsize=14)
|
|
333
|
-
|
|
334
|
-
|
|
364
|
+
if file is None:
|
|
365
|
+
plt.show()
|
|
366
|
+
else:
|
|
367
|
+
fig.savefig(file, bbox_inches='tight', pad_inches=0)
|
|
368
|
+
if show:
|
|
369
|
+
plt.show()
|
|
370
|
+
else:
|
|
371
|
+
plt.close(fig)
|
|
335
372
|
|
|
336
373
|
|
|
337
374
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|