Skip to content

Commit 2fd4b73

Browse files
committed
refactor: unify visualization method naming in ImageVisualizer
This commit refactors the ImageVisualizer class by renaming the `visualize_image` method to `visualize`, streamlining the interface for users. The updated method signature and examples in the docstring reflect this change, ensuring consistency in how predictions are visualized. Additionally, the copyright year has been updated to 2024-2025. Signed-off-by: Samet Akcay <samet.akcay@intel.com>
1 parent ca6c7ee commit 2fd4b73

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/anomalib/visualization/image/visualizer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2024 Intel Corporation
1+
# Copyright (C) 2024-2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

44
"""Image visualization module for anomaly detection.
@@ -16,7 +16,7 @@
1616
>>> # Create visualizer with default settings
1717
>>> visualizer = ImageVisualizer()
1818
>>> # Generate visualization
19-
>>> vis_result = visualizer.visualize(image=img, pred_mask=mask)
19+
>>> vis_result = visualizer.visualize(predictions)
2020
2121
The module ensures consistent visualization by:
2222
- Providing standardized field configurations
@@ -186,7 +186,7 @@ def __init__(
186186
self.text_config = {**DEFAULT_TEXT_CONFIG, **(text_config or {})}
187187
self.output_dir = output_dir
188188

189-
def visualize_image(
189+
def visualize(
190190
self,
191191
predictions: "ImageItem | NumpyImageItem | ImageBatch | NumpyImageBatch",
192192
) -> Image.Image | list[Image.Image | None] | None:
@@ -218,7 +218,7 @@ def visualize_image(
218218
... pred_mask=torch.rand(224, 224) > 0.5
219219
... )
220220
>>> visualizer = ImageVisualizer()
221-
>>> result = visualizer.visualize_image(item)
221+
>>> result = visualizer.visualize(item)
222222
>>> isinstance(result, Image.Image) or result is None
223223
True
224224
@@ -231,7 +231,7 @@ def visualize_image(
231231
... anomaly_map=np.random.rand(224, 224),
232232
... pred_mask=np.random.rand(224, 224) > 0.5
233233
... )
234-
>>> result = visualizer.visualize_image(item)
234+
>>> result = visualizer.visualize(item)
235235
>>> isinstance(result, Image.Image) or result is None
236236
True
237237
@@ -242,7 +242,7 @@ def visualize_image(
242242
... image=torch.rand(1, 3, 224, 224),
243243
... anomaly_map=torch.rand(1, 224, 224)
244244
... )
245-
>>> result = visualizer.visualize_image(single_batch)
245+
>>> result = visualizer.visualize(single_batch)
246246
>>> isinstance(result, Image.Image) or result is None
247247
True
248248
@@ -252,7 +252,7 @@ def visualize_image(
252252
... image=torch.rand(3, 3, 224, 224),
253253
... anomaly_map=torch.rand(3, 224, 224)
254254
... )
255-
>>> results = visualizer.visualize_image(multi_batch)
255+
>>> results = visualizer.visualize(multi_batch)
256256
>>> isinstance(results, list) and len(results) == 3
257257
True
258258
@@ -323,19 +323,19 @@ def __call__(
323323
"""Make the visualizer callable.
324324
325325
This method allows the visualizer to be used as a callable object.
326-
It behaves identically to the ``visualize_image`` method.
326+
It behaves identically to the ``visualize`` method.
327327
328328
Args:
329-
predictions: The predictions to visualize. Same as ``visualize_image``.
329+
predictions: The predictions to visualize. Same as ``visualize``.
330330
331331
Returns:
332-
Same as ``visualize_image`` method.
332+
Same as ``visualize`` method.
333333
334334
Examples:
335335
>>> visualizer = ImageVisualizer()
336-
>>> result = visualizer(predictions) # Equivalent to visualizer.visualize_image(predictions)
336+
>>> result = visualizer(predictions) # Equivalent to visualizer.visualize(predictions)
337337
"""
338-
return self.visualize_image(predictions)
338+
return self.visualize(predictions)
339339

340340
def on_test_batch_end(
341341
self,

0 commit comments

Comments
 (0)