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

data_exploration refactored

parent 8258ac8b
1 merge request!139Refactoring v1.0 prep
from . import colormaps
from .cc import plot_cc
from .detection import circles
from .explore import (
interactive_fade_mask,
orthogonal,
from .data_exploration import (
fade_mask,
slicer,
slices,
slicer_orthogonal,
slices_grid,
chunks,
histogram,
)
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 .structure_tensor import vectors
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
from qim3d.utils.misc import downscale_img, scale_to_float16
def vol(
def volumetric(
img,
aspectmode="data",
show=True,
save=False,
grid_visible=False,
cmap=None,
color_map='magma',
constant_opacity=False,
vmin=None,
vmax=None,
......@@ -43,8 +43,8 @@ def vol(
If a string is provided, it's interpreted as the file path where the HTML
file will be saved. 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.
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.
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 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.
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.
......@@ -60,7 +60,7 @@ def vol(
ValueError: If `aspectmode` is not `'data'` or `'cube'`.
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:
Display a volume inline:
......@@ -69,7 +69,7 @@ def vol(
import qim3d
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>
......@@ -78,7 +78,7 @@ def vol(
```python
import qim3d
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(
if vmax:
color_range[1] = vmax
# Handle the different formats that cmap can take
if cmap:
if isinstance(cmap, str):
cmap = plt.get_cmap(cmap) # Convert to Colormap object
if isinstance(cmap, Colormap):
# Convert to the format of cmap required by k3d.volume
attr_vals = np.linspace(0.0, 1.0, num=cmap.N)
RGB_vals = cmap(np.arange(0, cmap.N))[:, :3]
cmap = np.column_stack((attr_vals, RGB_vals)).tolist()
# Handle the different formats that color_map can take
if color_map:
if isinstance(color_map, str):
color_map = plt.get_cmap(color_map) # Convert to Colormap object
if isinstance(color_map, Colormap):
# Convert to the format of color_map required by k3d.volume
attr_vals = np.linspace(0.0, 1.0, num=color_map.N)
RGB_vals = color_map(np.arange(0, color_map.N))[:, :3]
color_map = np.column_stack((attr_vals, RGB_vals)).tolist()
# Default k3d.volume settings
opacity_function = []
interpolation = True
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)]
interpolation = False
......@@ -155,7 +155,7 @@ def vol(
if aspectmode.lower() == "data"
else None
),
color_map=cmap,
color_map=color_map,
samples=samples,
color_range=color_range,
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