diff --git a/docs/assets/screenshots/plot_cc_no_overlay.png b/docs/assets/screenshots/plot_cc_no_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..67724d1bc47e2122b918ae1a62ca18d64f0c1496 Binary files /dev/null and b/docs/assets/screenshots/plot_cc_no_overlay.png differ diff --git a/docs/assets/screenshots/plot_cc_overlay.png b/docs/assets/screenshots/plot_cc_overlay.png new file mode 100644 index 0000000000000000000000000000000000000000..7d9a79fd385b29225de6636cc445d68189296385 Binary files /dev/null and b/docs/assets/screenshots/plot_cc_overlay.png differ diff --git a/docs/releases.md b/docs/releases.md index 3265d5d23a46170c81e56bca22d4ca46441d4894..b4e7ba33ef6844134b20133c9d178076cdf255fa 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -9,16 +9,22 @@ As the library is still in its early development stages, **there may be breaking And remember to keep your pip installation [up to date](/qim3d/#upgrade) so that you have the latest features! +### v0.3.4 (coming soon!) +- Documentation for `qim3d.viz.plot_cc` + + ### v0.3.3 (11/04/2024) - Introduction of `qim3d.viz.slicer` (and also `qim3d.viz.orthogonal` ) 🎉 - Introduction of `qim3d.gui.annotation_tool` 🎉 - Introduction of `qim3d.processing.Blob` for blob detection 🎉 - Introduction of `qim3d.processing.local_thickness` 🎉 - Introduction of `qim3d.processing.structure_tensor` 🎉 -- Support for loading DICOM files with `qim3d.io.load`🎉 +- Support for loading DICOM files with `qim3d.io.load` - Introduction of `qim3d.processing.get_3d_cc` for 3D connected components and `qim3d.viz.plot_cc` for associated visualization 🎉 - Introduction of `qim3d.viz.colormaps` for easy visualization of e.g. multi-label segmentation results 🎉 - Introduction of `qim3d.processing.operations.background_removal` 🎉 +- Documentation refactoring +- Fixed bug preventing `Data Explorer` to show files ### v0.3.2 (23/02/2024) diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css index ba35334e9ec9ce511401849f4ea207e947499321..d5d3f1dc12f7d5e3b213b22eee651ee3cef48ae2 100644 --- a/docs/stylesheets/extra.css +++ b/docs/stylesheets/extra.css @@ -96,4 +96,8 @@ code { .md-typeset .admonition.example, .md-typeset details.example { border-color: #ff9900; +} + +.md-typeset .example>.admonition-title:after, .md-typeset .example>summary:after { + color: #ff9900; } \ No newline at end of file diff --git a/qim3d/processing/cc.py b/qim3d/processing/cc.py index 0cc7cee7f18411ece830e0bf8f72c87bbcd47ff0..d6ec0e85d0510267704ed048f89e6a150d5f8ecf 100644 --- a/qim3d/processing/cc.py +++ b/qim3d/processing/cc.py @@ -72,7 +72,7 @@ class CC: def get_3d_cc(image: np.ndarray | torch.Tensor) -> CC: - """ Get the connected components of a 3D volume. + """ Returns an object (CC) containing the connected components of the input volume. Use plot_cc to visualize the connected components. Args: image (np.ndarray | torch.Tensor): An array-like object to be labeled. Any non-zero values in `input` are @@ -80,8 +80,14 @@ def get_3d_cc(image: np.ndarray | torch.Tensor) -> CC: Returns: CC: A ConnectedComponents object containing the connected components and the number of connected components. + + Example: + ```python + import qim3d + vol = qim3d.examples.cement_128x128x128[50:150]<60 + cc = qim3d.processing.get_3d_cc(vol) + ``` """ connected_components, num_connected_components = label(image) log.info(f"Total number of connected components found: {num_connected_components}") - return CC(connected_components, num_connected_components) diff --git a/qim3d/viz/cc.py b/qim3d/viz/cc.py index 0f3ac8fdf0f84240088ab8c9b5eb76da9624aaa3..7efee4923463ee44419b54443d06896c9cbd8436 100644 --- a/qim3d/viz/cc.py +++ b/qim3d/viz/cc.py @@ -1,8 +1,11 @@ -import numpy as np import matplotlib.pyplot as plt +import numpy as np + +from qim3d.io.logger import log +from qim3d.processing.cc import CC from qim3d.viz import slices from qim3d.viz.colormaps import objects as qim3dCmap -from qim3d.processing.cc import CC + def plot_cc( connected_components, @@ -14,11 +17,11 @@ def plot_cc( **kwargs, ) -> list[plt.Figure]: """ - Plot the connected components of an image. + Plots the connected components from a `qim3d.processing.cc.CC` object. If an overlay image is provided, the connected component will be masked to the overlay image. Parameters: connected_components (CC): The connected components object. - components (list | tuple, optional): The components to plot. If None the first max_cc_to_plot=32 components will be plotted. Defaults to None. + component_indexs (list | tuple, optional): The components to plot. If None the first max_cc_to_plot=32 components will be plotted. Defaults to None. max_cc_to_plot (int, optional): The maximum number of connected components to plot. Defaults to 32. overlay (optional): Overlay image. Defaults to None. crop (bool, optional): Whether to crop the image to the cc. Defaults to False. @@ -27,6 +30,18 @@ def plot_cc( Returns: figs (list[plt.Figure]): List of figures, if `show=False`. + + Example: + ```python + import qim3d + vol = qim3d.examples.cement_128x128x128[50:150] + vol_bin = vol<80 + cc = qim3d.processing.get_3d_cc(vol_bin) + qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=None, n_slices=5, component_indexs=[4,6,7]) + qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=vol, n_slices=5, component_indexs=[4,6,7]) + ``` +  +  """ # if no components are given, plot the first max_cc_to_plot=32 components if component_indexs is None: