|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import TYPE_CHECKING |
8 | 8 |
|
| 9 | +import numpy as np |
9 | 10 | from magicgui import magicgui |
10 | 11 | from magicgui.widgets import Container, Label, PushButton |
11 | | -from napari.layers import Layer |
| 12 | +from napari.layers import Layer, Shapes |
12 | 13 | from napari.utils.notifications import show_error, show_info |
13 | 14 | from qtpy.QtWidgets import QFileDialog |
14 | 15 |
|
@@ -160,6 +161,7 @@ def _update_branch_color_warning(*args) -> None: |
160 | 161 | self.branch_color_warning.visible = needs_radius and radius_off |
161 | 162 |
|
162 | 163 | self.branch_color_widget.changed.connect(_update_branch_color_warning) |
| 164 | + self.branch_color_widget.changed.connect(self._recolor_branch_layers) |
163 | 165 |
|
164 | 166 | # connection to include_vessel_radius_widget happens below |
165 | 167 | # after that widget is created |
@@ -427,6 +429,29 @@ def _on_select_output_dir(self) -> None: |
427 | 429 | self._output_dir = Path(dir_path) |
428 | 430 | self.select_outdir_btn.text = str(self._output_dir) |
429 | 431 |
|
| 432 | + def _recolor_branch_layers(self, *args) -> None: |
| 433 | + """Recolor existing branch layers without re-running analysis.""" |
| 434 | + prop = self.branch_color_widget.value |
| 435 | + |
| 436 | + for layer in self.viewer.layers: |
| 437 | + if not isinstance(layer, Shapes) or not layer.name.endswith("_branches"): |
| 438 | + continue |
| 439 | + |
| 440 | + props = layer.properties |
| 441 | + values = props.get(prop) if props is not None else None |
| 442 | + if values is not None: |
| 443 | + numeric = np.asarray(values, dtype=float) |
| 444 | + finite = numeric[np.isfinite(numeric)] |
| 445 | + if finite.size > 1 and float(np.min(finite)) < float(np.max(finite)): |
| 446 | + vmin = float(np.min(finite)) |
| 447 | + vmax = float(np.max(finite)) |
| 448 | + layer.edge_color = prop |
| 449 | + layer.edge_colormap = "turbo" |
| 450 | + layer.edge_contrast_limits = (vmin, vmax) |
| 451 | + continue |
| 452 | + |
| 453 | + layer.edge_color = "#30d5c8" |
| 454 | + |
430 | 455 | def _on_analyze(self) -> None: |
431 | 456 | """Execute analysis with current settings.""" |
432 | 457 | img = self.image_widget.value |
|
0 commit comments