garmentiq.landmark.plot

 1import matplotlib.pyplot as plt
 2import numpy as np
 3from PIL import Image
 4
 5
 6def plot(
 7    image_path: str,
 8    coordinate: np.ndarray = None,
 9    figsize: tuple = (6, 6),
10    color: str = "red",
11):
12    """
13    Display an image from a file path using matplotlib, with optional overlay of coordinates.
14
15    This function loads an image from the given file path, displays it using matplotlib,
16    and optionally overlays coordinate points on the image.
17
18    Args:
19        image_path (str): Path to the image file. The image will be loaded as RGB.
20        coordinate (np.ndarray, optional): Optional array of coordinates to overlay on the image.
21                                          Expected shape: (1, N, 2), where N is the number of points.
22        figsize (tuple, optional): Size of the displayed figure in inches (width, height).
23        color (str, optional): Color of the overlay points. Default is 'red'.
24
25    Raises:
26        ValueError: If image cannot be loaded or coordinate format is invalid.
27
28    Returns:
29        None
30    """
31    try:
32        image_np = np.array(Image.open(image_path).convert("RGB"))
33    except Exception as e:
34        raise ValueError(f"Unable to load image from path: {image_path}. Error: {e}")
35
36    plt.figure(figsize=figsize)
37
38    if image_np.ndim == 2:
39        plt.imshow(image_np, cmap="gray")
40    else:
41        plt.imshow(image_np)
42
43    if coordinate is not None:
44        try:
45            plt.scatter(coordinate[0][:, 0], coordinate[0][:, 1], c=color, s=10)
46        except Exception as e:
47            raise ValueError(f"Invalid coordinate format: {coordinate}. Error: {e}")
48
49    plt.axis("off")
50    plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
51    plt.show()
def plot( image_path: str, coordinate: numpy.ndarray = None, figsize: tuple = (6, 6), color: str = 'red'):
 7def plot(
 8    image_path: str,
 9    coordinate: np.ndarray = None,
10    figsize: tuple = (6, 6),
11    color: str = "red",
12):
13    """
14    Display an image from a file path using matplotlib, with optional overlay of coordinates.
15
16    This function loads an image from the given file path, displays it using matplotlib,
17    and optionally overlays coordinate points on the image.
18
19    Args:
20        image_path (str): Path to the image file. The image will be loaded as RGB.
21        coordinate (np.ndarray, optional): Optional array of coordinates to overlay on the image.
22                                          Expected shape: (1, N, 2), where N is the number of points.
23        figsize (tuple, optional): Size of the displayed figure in inches (width, height).
24        color (str, optional): Color of the overlay points. Default is 'red'.
25
26    Raises:
27        ValueError: If image cannot be loaded or coordinate format is invalid.
28
29    Returns:
30        None
31    """
32    try:
33        image_np = np.array(Image.open(image_path).convert("RGB"))
34    except Exception as e:
35        raise ValueError(f"Unable to load image from path: {image_path}. Error: {e}")
36
37    plt.figure(figsize=figsize)
38
39    if image_np.ndim == 2:
40        plt.imshow(image_np, cmap="gray")
41    else:
42        plt.imshow(image_np)
43
44    if coordinate is not None:
45        try:
46            plt.scatter(coordinate[0][:, 0], coordinate[0][:, 1], c=color, s=10)
47        except Exception as e:
48            raise ValueError(f"Invalid coordinate format: {coordinate}. Error: {e}")
49
50    plt.axis("off")
51    plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
52    plt.show()

Display an image from a file path using matplotlib, with optional overlay of coordinates.

This function loads an image from the given file path, displays it using matplotlib, and optionally overlays coordinate points on the image.

Arguments:
  • image_path (str): Path to the image file. The image will be loaded as RGB.
  • coordinate (np.ndarray, optional): Optional array of coordinates to overlay on the image. Expected shape: (1, N, 2), where N is the number of points.
  • figsize (tuple, optional): Size of the displayed figure in inches (width, height).
  • color (str, optional): Color of the overlay points. Default is 'red'.
Raises:
  • ValueError: If image cannot be loaded or coordinate format is invalid.
Returns:

None