From c1e679f78f0ac100afa960724a43dbf1a881b56b Mon Sep 17 00:00:00 2001 From: Felipe <fima@dtu.dk> Date: Thu, 11 Apr 2024 12:58:30 +0200 Subject: [PATCH] refactoring for the colormap call --- .../screenshots/viz-colormaps-objects.png | Bin 0 -> 1115 bytes docs/viz.md | 5 +++ qim3d/viz/__init__.py | 4 +- qim3d/viz/colormaps.py | 38 +++++++++++++----- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 docs/assets/screenshots/viz-colormaps-objects.png diff --git a/docs/assets/screenshots/viz-colormaps-objects.png b/docs/assets/screenshots/viz-colormaps-objects.png new file mode 100644 index 0000000000000000000000000000000000000000..a9dc2e38dbeacf41d85ba30e531f6c90ab791ef8 GIT binary patch literal 1115 zcmeAS@N?(olHy`uVBq!ia0y~yU}9ikU~u4IV_;y&*?)dN0|SF}iEBhjNM=b+Dnou! zR%&udaeQ)aVu3<(eolT-ZeqbDpAG*Q7#I{m%3M;5lZ!G7N;32FuqzI@8dc4}z+eDU z>{wcokzd5%n^;nilV6gPnWRu=tY@KTprepcQc_TCrLUh0m(t5GN}pf+!=HhH!3d-` zI6tkVJh3R1c-<SXre`oPFo$@$IEGZrd3)_*_SICG;~&%0`b;EE76+<Ha=x0|<ft-L zYU+il0vuhL9cELc5_@Hi?pdK4na2^EG0}135v4Ab$qVB`5)$u9%#3ppQZw!JC=T55 zuff0G@&5JKpUztTkvmt(_x$q3sM$IHAD+7Bd$F&d&vp0fBL!Qgitk?hm1k{#*^|5W zi|5|oWOD1de4X&yd(m;-W>>yPY`K@7?iOA0qB|p6eSLpfNs{B1i|Jvmvx~mo&RDzk z+p+cOi(+N=$-Le5{qtVybGAac=cgUM`0cEX^xH#sZr&7o-}CM7NA8Px@&Br}T=jo4 zQ(bO`(Ay7pA}@aX?&q@m=gHWMR^ngWXYbXTe>*BWxmeFt+J5f(-D&yZTXOZE*IHcP zZ+mNF-=6r>=Ko~YzP^w!@9CMX7t3U8v~F9wFWTCx?>ejM{FaRAe0H+A-xpV|XSe%d zbnD2Wqd)IlyS2-@+~xPW=UH3i{qD-=KJVGXAOCmq{`r-$mGSpyf6bhinp<~#uJ>n2 z>AbsAxyL?lcb)z3@}3Oyd9@a|<h4KZ#aEW*ZK>Vu?`r+isV;2oR<j*BCbyPN{`v3f z{(7OeuP4^rt*!N5r2DeY=GKXb{4JfLwHKf5pLG9s*GB0@bL+E<x7^?L+~s%S`QnS) z*8bPH70=J>F8$-F!<J6d;Kf_7-D;d?^LW!$=E`|5k8iTAFu8RiJ$upH|3A)V=+Ar6 zQ}+Ga&x>s8pZDi{zW?~*vbB3PZ#`KwG2`*_`+e8!cPZYIoo>A-H)@AoRQB4Z`dkb@ q?i({OEKp!(VBj(uWgrE@FY#4@(=Kgk-X#YrJ3L+eT-G@yGywofSF(2i literal 0 HcmV?d00001 diff --git a/docs/viz.md b/docs/viz.md index bc729bc1..604b3a59 100644 --- a/docs/viz.md +++ b/docs/viz.md @@ -11,4 +11,9 @@ The `qim3d` library aims to provide easy ways to explore and get insights from v - local_thickness - vectors - plot_cc + - colormaps + +::: qim3d.viz.colormaps + options: + members: - objects diff --git a/qim3d/viz/__init__.py b/qim3d/viz/__init__.py index 54a1b11b..1a9c76da 100644 --- a/qim3d/viz/__init__.py +++ b/qim3d/viz/__init__.py @@ -4,5 +4,7 @@ from .k3d import vol from .structure_tensor import vectors from .local_thickness_ import local_thickness from .cc import plot_cc -from .colormaps import objects +#from .colormaps import objects +from . import colormaps + from .detection import circles diff --git a/qim3d/viz/colormaps.py b/qim3d/viz/colormaps.py index a32b7784..fb146071 100644 --- a/qim3d/viz/colormaps.py +++ b/qim3d/viz/colormaps.py @@ -1,5 +1,9 @@ +""" +This module provides a collection of colormaps useful for 3D visualization. +""" + import colorsys - +from typing import Union, Tuple import numpy as np from matplotlib.colors import LinearSegmentedColormap @@ -7,25 +11,37 @@ from qim3d.io.logger import log def objects( - nlabels, - style="bright", - first_color_background=True, - last_color_background=False, - background_color=(0.0, 0.0, 0.0), - seed=19, -): + nlabels: int, + style: str = "bright", + first_color_background: bool = True, + last_color_background: bool = False, + background_color: Union[Tuple[float, float, float], str] = (0.0, 0.0, 0.0), + seed: int = 19, +) -> LinearSegmentedColormap: """ Creates a random colormap to be used together with matplotlib. Useful for segmentation tasks Args: - nlabels (int): Number of labels (size of colormap) + nlabels (int): Number of labels (size of colormap). style (str, optional): 'bright' for strong colors, 'soft' for pastel colors. Defaults to 'bright'. - first_color_background (bool, optional): Option to use first color as background. Defaults to True. - last_color_background (bool, optional): Option to use last color as background. Defaults to False. + first_color_background (bool, optional): If True, the first color is used as background. Defaults to True. + last_color_background (bool, optional): If True, the last color is used as background. Defaults to False. + background_color (tuple or str, optional): RGB tuple or string for background color. Can be "black" or "white". Defaults to (0.0, 0.0, 0.0). seed (int, optional): Seed for random number generator. Defaults to 19. Returns: cmap (matplotlib.colors.LinearSegmentedColormap): Colormap for matplotlib + + + Example: + ```python + import qim3d + + cmap = qim3d.viz.colormaps.objects(nlabels=100, first_color_background=True, background_color="black") + display(cmap) + ``` +  + """ # Check style if style not in ("bright", "soft"): -- GitLab