Skip to content

Commit

Permalink
merging tutorial notebooks for visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
cinarturhan committed Nov 26, 2024
2 parents 4b966e6 + afe1e59 commit ece2767
Show file tree
Hide file tree
Showing 4 changed files with 742 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dpm_tools/io/_read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _not_implemented():
raise NotImplementedError("No support for this datafile type... yet")


def read_image(read_path: pathlib.Path, **kwargs) -> np.ndarray:
def read_image(read_path: str, **kwargs) -> np.ndarray:
"""
A general use function for reading in an image of the implemented filetypes
Currently supports reading in tiff, raw, and mat.
Expand All @@ -193,6 +193,7 @@ def read_image(read_path: pathlib.Path, **kwargs) -> np.ndarray:
Returns:
np.ndarray: The image array
"""
read_path = pathlib.Path(read_path)

filetypes = {'.tiff': _read_tiff,
'.tif': _read_tiff,
Expand Down
10 changes: 7 additions & 3 deletions dpm_tools/visualization/_plot_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def orthogonal_slices(data, fig: pv.DataSet = None, show_slices: list = None, pl
Plots 3 orthogonal slices of a 3D image.
Parameters:
data: A dataclass containing 3D image data
data: A np array containing 3D image data
fig: Pyvista plotter object
show_slices: List of slices in x, y, z to show. Default is middle slice in each direction.
plotter_kwargs: Additional keyword arguments to pass to the plotter.
Expand Down Expand Up @@ -40,6 +40,7 @@ def orthogonal_slices(data, fig: pv.DataSet = None, show_slices: list = None, pl
assert 0 <= y_slice < data.ny, "Y-slice value outside image dimensions"
assert 0 <= z_slice < data.nz, "Z-slice value outside image dimensions"


# Initialize plotter object
if fig is None:
fig = _initialize_plotter(**plotter_kwargs)
Expand Down Expand Up @@ -162,7 +163,9 @@ def plot_isosurface(data, fig: pv.Plotter = None, show_isosurface: list = None,
if fig is None:
fig = _initialize_plotter(**plotter_kwargs)


pv_image_obj = _wrap_array(data.scalar)


if show_isosurface is None:
show_isosurface = [(np.amax(data.scalar)+np.amin(data.scalar))/2]
Expand Down Expand Up @@ -239,9 +242,9 @@ def plot_glyph(vector_data, fig: pv.Plotter = None, glyph: pv.PolyData = None, g
'factor': scale_factor}

if vector_data.vector is not None:
glyph_kwargs['orient'] = [vector_data.vector[i][::glyph_space, ::glyph_space,
::glyph_space]/np.max(vector_data.magnitude) for i in range(3)]
glyph_kwargs['orient'] = [vector_data.vector[i][::glyph_space, ::glyph_space, ::glyph_space]/np.max(vector_data.magnitude) for i in range(3)]

# plotter_kwargs, mesh_kwargs = _initialize_kwargs(plotter_kwargs, mesh_kwargs)
x, y, z = np.mgrid[:vector_data.nx:glyph_space,
:vector_data.ny:glyph_space,
:vector_data.nz:glyph_space]
Expand Down Expand Up @@ -422,6 +425,7 @@ def plot_medial_axis(data, fig: pv.Plotter = None, show_isosurface: list = None,
fig = _initialize_plotter(**plotter_kwargs)

medial_axis = skimage.morphology.skeletonize(data.scalar)

pv_image_obj = _wrap_array(medial_axis)

contours_ma = pv_image_obj.contour(isosurfaces=[0.5])
Expand Down
391 changes: 391 additions & 0 deletions examples/Vector_Field_Visualization_Tutorial.ipynb

Large diffs are not rendered by default.

342 changes: 342 additions & 0 deletions examples/Visualization_Tools_Tutorial.ipynb

Large diffs are not rendered by default.

0 comments on commit ece2767

Please sign in to comment.