From 6ba5e8b0bd9f7ebf32a532933b050b4877be0538 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Mon, 23 Nov 2026 18:37:21 +1000 Subject: [PATCH] chore: annotate ImageIO Part of Issue 60. Types showwindow(h, ax), the Window helper class and the stereo Cursor class, and gives the mixin a docstring. Drops a :type: line that the signature now gives. Co-Authored-By: Claude Sonnet 5.5 --- src/machinevisiontoolbox/ImageIO.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/machinevisiontoolbox/ImageIO.py b/src/machinevisiontoolbox/ImageIO.py index 92d5c69e..411bf6af 100644 --- a/src/machinevisiontoolbox/ImageIO.py +++ b/src/machinevisiontoolbox/ImageIO.py @@ -6,7 +6,7 @@ import os.path import sys from pathlib import Path -from typing import TYPE_CHECKING, Any, SupportsFloat, cast +from typing import Any, SupportsFloat, cast if sys.version_info >= (3, 11): from typing import Self @@ -18,13 +18,11 @@ import matplotlib.pyplot as plt import numpy as np import PIL.Image +from matplotlib.axes import Axes from matplotlib.colors import Colormap, LinearSegmentedColormap from PIL.ExifTags import TAGS from spatialmath.base import set_window_title -if TYPE_CHECKING: - pass - from machinevisiontoolbox._image_typing import ImageMixinBase from machinevisiontoolbox.base.imageio import ( _pick_imagefile, @@ -39,6 +37,10 @@ class ImageIOMixin(ImageMixinBase): + """ + Methods of :class:`Image` that read, write and display images + """ + # ======================= image i/io ================================== # @classmethod @@ -448,12 +450,11 @@ def showpixels( plt.draw() return ax - def showwindow(self, h, ax=None, **kwargs: Any) -> Any: + def showwindow(self, h: int, ax: Axes | None = None, **kwargs: Any) -> Any: """Superimpose a colored window on the image. :param h: The half-width of the window, so the total window size is (2h+1)x(2h+1) - :type h: int :param ax: The axes on which to display the window, defaults to the current axes :return: The window instance @@ -513,7 +514,13 @@ def showwindow(self, h, ax=None, **kwargs: Any) -> Any: """ class Window: - def __init__(self, h=1, ax=None, image=None, **kwargs: Any) -> None: + def __init__( + self, + h: int = 1, + ax: Axes | None = None, + image: ImageMixinBase | None = None, + **kwargs: Any, + ) -> None: self.h = h self.image = image self.args = kwargs @@ -701,7 +708,7 @@ class Cursor: A cross hair cursor. """ - def __init__(self, ax, ax2): + def __init__(self, ax: Axes, ax2: Axes) -> None: self.ax = ax self.ax2 = ax2 self.horizontal_line = ax.axhline(color="k", lw=0.8)