Skip to content
Snippets Groups Projects
Commit 5505b582 authored by fima's avatar fima 🍻
Browse files

data_exploration refactored

parent 8258ac8b
No related branches found
No related tags found
1 merge request!139Refactoring v1.0 prep
This commit is part of merge request !139. Comments created here will be created in the context of that merge request.
from . import colormaps from . import colormaps
from .cc import plot_cc from .cc import plot_cc
from .detection import circles from .detection import circles
from .explore import ( from .data_exploration import (
interactive_fade_mask, fade_mask,
orthogonal,
slicer, slicer,
slices, slicer_orthogonal,
slices_grid,
chunks, chunks,
histogram, histogram,
) )
from .itk_vtk_viewer import itk_vtk, Installer, NotInstalledError from .itk_vtk_viewer import itk_vtk, Installer, NotInstalledError
from .k3d import vol, mesh from .k3d import volumetric, mesh
from .local_thickness_ import local_thickness from .local_thickness_ import local_thickness
from .structure_tensor import vectors from .structure_tensor import vectors
from .metrics import plot_metrics, grid_overview, grid_pred, vol_masked from .metrics import plot_metrics, grid_overview, grid_pred, vol_masked
......
This diff is collapsed.
...@@ -14,13 +14,13 @@ from qim3d.utils.logger import log ...@@ -14,13 +14,13 @@ from qim3d.utils.logger import log
from qim3d.utils.misc import downscale_img, scale_to_float16 from qim3d.utils.misc import downscale_img, scale_to_float16
def vol( def volumetric(
img, img,
aspectmode="data", aspectmode="data",
show=True, show=True,
save=False, save=False,
grid_visible=False, grid_visible=False,
cmap=None, color_map='magma',
constant_opacity=False, constant_opacity=False,
vmin=None, vmin=None,
vmax=None, vmax=None,
...@@ -43,8 +43,8 @@ def vol( ...@@ -43,8 +43,8 @@ def vol(
If a string is provided, it's interpreted as the file path where the HTML If a string is provided, it's interpreted as the file path where the HTML
file will be saved. Defaults to False. file will be saved. Defaults to False.
grid_visible (bool, optional): If True, the grid is visible in the plot. Defaults to False. grid_visible (bool, optional): If True, the grid is visible in the plot. Defaults to False.
cmap (str or matplotlib.colors.Colormap or list, optional): The color map to be used for the volume rendering. If a string is passed, it should be a matplotlib colormap name. Defaults to None. color_map (str or matplotlib.colors.Colormap or list, optional): The color map to be used for the volume rendering. If a string is passed, it should be a matplotlib colormap name. Defaults to None.
constant_opacity (bool, float): Set to True if doing an object label visualization with a corresponding cmap; otherwise, the plot may appear poorly. Defaults to False. constant_opacity (bool, float): Set to True if doing an object label visualization with a corresponding color_map; otherwise, the plot may appear poorly. Defaults to False.
vmin (float, optional): Together with vmax defines the data range the colormap covers. By default colormap covers the full range. Defaults to None. vmin (float, optional): Together with vmax defines the data range the colormap covers. By default colormap covers the full range. Defaults to None.
vmax (float, optional): Together with vmin defines the data range the colormap covers. By default colormap covers the full range. Defaults to None vmax (float, optional): Together with vmin defines the data range the colormap covers. By default colormap covers the full range. Defaults to None
samples (int, optional): The number of samples to be used for the volume rendering in k3d. Defaults to 512. samples (int, optional): The number of samples to be used for the volume rendering in k3d. Defaults to 512.
...@@ -60,7 +60,7 @@ def vol( ...@@ -60,7 +60,7 @@ def vol(
ValueError: If `aspectmode` is not `'data'` or `'cube'`. ValueError: If `aspectmode` is not `'data'` or `'cube'`.
Tip: Tip:
The function can be used for object label visualization using a `cmap` created with `qim3d.viz.colormaps.objects` along with setting `objects=True`. The latter ensures appropriate rendering. The function can be used for object label visualization using a `color_map` created with `qim3d.viz.colormaps.objects` along with setting `objects=True`. The latter ensures appropriate rendering.
Example: Example:
Display a volume inline: Display a volume inline:
...@@ -69,7 +69,7 @@ def vol( ...@@ -69,7 +69,7 @@ def vol(
import qim3d import qim3d
vol = qim3d.examples.bone_128x128x128 vol = qim3d.examples.bone_128x128x128
qim3d.viz.vol(vol) qim3d.viz.volumetric(vol)
``` ```
<iframe src="https://platform.qim.dk/k3d/fima-bone_128x128x128-20240221113459.html" width="100%" height="500" frameborder="0"></iframe> <iframe src="https://platform.qim.dk/k3d/fima-bone_128x128x128-20240221113459.html" width="100%" height="500" frameborder="0"></iframe>
...@@ -78,7 +78,7 @@ def vol( ...@@ -78,7 +78,7 @@ def vol(
```python ```python
import qim3d import qim3d
vol = qim3d.examples.bone_128x128x128 vol = qim3d.examples.bone_128x128x128
plot = qim3d.viz.vol(vol, show=False, save="plot.html") plot = qim3d.viz.volumetric(vol, show=False, save="plot.html")
``` ```
""" """
...@@ -129,21 +129,21 @@ def vol( ...@@ -129,21 +129,21 @@ def vol(
if vmax: if vmax:
color_range[1] = vmax color_range[1] = vmax
# Handle the different formats that cmap can take # Handle the different formats that color_map can take
if cmap: if color_map:
if isinstance(cmap, str): if isinstance(color_map, str):
cmap = plt.get_cmap(cmap) # Convert to Colormap object color_map = plt.get_cmap(color_map) # Convert to Colormap object
if isinstance(cmap, Colormap): if isinstance(color_map, Colormap):
# Convert to the format of cmap required by k3d.volume # Convert to the format of color_map required by k3d.volume
attr_vals = np.linspace(0.0, 1.0, num=cmap.N) attr_vals = np.linspace(0.0, 1.0, num=color_map.N)
RGB_vals = cmap(np.arange(0, cmap.N))[:, :3] RGB_vals = color_map(np.arange(0, color_map.N))[:, :3]
cmap = np.column_stack((attr_vals, RGB_vals)).tolist() color_map = np.column_stack((attr_vals, RGB_vals)).tolist()
# Default k3d.volume settings # Default k3d.volume settings
opacity_function = [] opacity_function = []
interpolation = True interpolation = True
if constant_opacity: if constant_opacity:
# without these settings, the plot will look bad when cmap is created with qim3d.viz.colormaps.objects # without these settings, the plot will look bad when color_map is created with qim3d.viz.colormaps.objects
opacity_function = [0.0, float(constant_opacity), 1.0, float(constant_opacity)] opacity_function = [0.0, float(constant_opacity), 1.0, float(constant_opacity)]
interpolation = False interpolation = False
...@@ -155,7 +155,7 @@ def vol( ...@@ -155,7 +155,7 @@ def vol(
if aspectmode.lower() == "data" if aspectmode.lower() == "data"
else None else None
), ),
color_map=cmap, color_map=color_map,
samples=samples, samples=samples,
color_range=color_range, color_range=color_range,
opacity_function=opacity_function, opacity_function=opacity_function,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment