1212 from scportrait .pipeline .project import Project
1313
1414
15- def plot_image (
15+ from scportrait ._utils .deprecation import deprecated
16+
17+
18+ def plot_image_array (
1619 array : np .ndarray ,
1720 size : tuple [int , int ] = (10 , 10 ),
1821 save_name : str | None = "" ,
@@ -34,11 +37,11 @@ def plot_image(
3437 **kwargs: Additional keyword arguments to be passed to `ax.imshow`.
3538
3639 Returns:
37- None: The function will display the image but does not return any values .
40+ Matplotlib figure if `return_fig=True`, otherwise `None` .
3841
3942 Example:
4043 >>> array = np.random.rand(10, 10)
41- >>> plot_image (array, size=(5, 5))
44+ >>> plot_image_array (array, size=(5, 5))
4245 """
4346
4447 fig = plt .figure (frameon = False )
@@ -60,12 +63,25 @@ def plot_image(
6063 plt .close ()
6164
6265
66+ @deprecated (
67+ deprecated_in = "1.6.2" ,
68+ removed_in = "1.7.0" ,
69+ details = (
70+ "This function is not used internally and will be removed in a future release. "
71+ "Prefer scportrait.plotting.sdata.plot_labels or scportrait.plotting.sdata.plot_shapes."
72+ ),
73+ )
6374def visualize_class (
6475 class_ids : np .ndarray | list [int ], seg_map : np .ndarray , image : np .ndarray , all_ids = None , return_fig = False , ** kwargs
6576):
6677 """
6778 Visualize specific classes in a segmentation map by highlighting them on top of a background image.
6879
80+ .. deprecated:: 1.6.2
81+ This function is not used internally and will be removed in a future release. Prefer
82+ `scportrait.plotting.sdata.plot_labels` or `scportrait.plotting.sdata.plot_shapes` for
83+ SpatialData-based workflows.
84+
6985 This function takes in class IDs and a segmentation map, and creates an output visualization
7086 where the specified classes are highlighted on top of the provided background image.
7187
@@ -106,12 +122,20 @@ def visualize_class(
106122
107123 vis_map = label2rgb (outmap , image = image , colors = ["red" , "blue" ], alpha = 0.4 , bg_label = 0 )
108124
109- fig = plot_image (vis_map , return_fig = True , ** kwargs )
125+ fig = plot_image_array (vis_map , return_fig = True , ** kwargs )
110126
111127 if return_fig :
112128 return fig
113129
114130
131+ @deprecated (
132+ deprecated_in = "1.6.2" ,
133+ removed_in = "1.7.0" ,
134+ details = (
135+ "This helper is superseded by scportrait.plotting.sdata.plot_segmentation_mask and "
136+ "is not used internally. It will be removed in a future release."
137+ ),
138+ )
115139def plot_segmentation_mask (
116140 project : Project ,
117141 mask_channel : int = 0 ,
@@ -124,6 +148,10 @@ def plot_segmentation_mask(
124148) -> object :
125149 """Visualize the segmentation mask overlayed with a channel of the input image.
126150
151+ .. deprecated:: 1.6.2
152+ This helper is superseded by `scportrait.plotting.sdata.plot_segmentation_mask` and
153+ is not used internally. It will be removed in a future release.
154+
127155 Args:
128156 project: Instance of a scPortrait project.
129157 mask_channel: The index of the channel to use for the segmentation mask.
@@ -167,17 +195,22 @@ def colorize(
167195 im : np .ndarray , color : tuple [int , ...] = (1 , 0 , 0 ), clip_percentile : float = 0.0 , normalize_image : bool = False
168196):
169197 """
170- Helper function to create an RGB image from a single-channel image using a
171- specific color.
198+ Create an RGB image from a single-channel image using a specified color.
172199
173200 Args:
174- im: A single-channel input image. If normalize_image = False, ensure that its values fall between the [0, 1] range .
201+ im: A single-channel input image. If normalize_image = False, ensure that its values fall between [0, 1].
175202 color: The color to use for the image. Defaults to (1, 0, 0).
176- clip_percentile: The percentile to clip the image at rescaling. Defaults to 0.0 which is equivalent to Min-Max scaling.
177- normalize_image: boolean value indicating if rescaling should be performed or not .
203+ clip_percentile: Percentile to clip the image at when rescaling. Defaults to 0.0 (min-max scaling) .
204+ normalize_image: Whether to rescale the image before colorizing .
178205
179206 Returns:
180207 np.ndarray: The colorized image.
208+
209+ Example:
210+ >>> import numpy as np
211+ >>> from scportrait.plotting import colorize
212+ >>> im = np.random.rand(64, 64)
213+ >>> rgb = colorize(im, color=(0, 1, 0), normalize_image=True)
181214 """
182215 # Check that we do just have a 2D image
183216 if im .ndim > 2 and im .shape [2 ] != 1 :
0 commit comments