garmentiq.segmentation.plot
Displaying an image, mask, or background-modified result.
1"""Displaying an image, mask, or background-modified result.""" 2import matplotlib.pyplot as plt 3import numpy as np 4 5 6def plot(image_np: np.ndarray, figsize: tuple = (6, 6)): 7 """ 8 Displays an image using matplotlib, with optional customization of the figure size. 9 10 This function takes an image in the form of a NumPy array and displays it using matplotlib. 11 If the image is 2D (grayscale), it will use a grayscale colormap for visualization. 12 It also provides an option to adjust the figure size via the `figsize` parameter. 13 14 Args: 15 image_np (numpy.ndarray): The image to be displayed. Can be either 2D (grayscale) or 3D (color) numpy array. 16 figsize (tuple, optional): The size of the figure (width, height). Default is (6, 6). 17 18 Raises: 19 ValueError: If the image provided is not a numpy array. 20 21 Returns: 22 None. The function directly displays the image. 23 """ 24 plt.figure(figsize=figsize) 25 26 # If the image is 2D (grayscale), use 'gray' colormap for a black & white mask 27 if image_np.ndim == 2: 28 plt.imshow(image_np, cmap="gray") 29 else: 30 plt.imshow(image_np) 31 32 # Remove axis and padding around the plot 33 plt.axis("off") 34 plt.subplots_adjust(left=0, right=1, top=1, bottom=0) 35 plt.show()
def
plot(image_np: numpy.ndarray, figsize: tuple = (6, 6)):
7def plot(image_np: np.ndarray, figsize: tuple = (6, 6)): 8 """ 9 Displays an image using matplotlib, with optional customization of the figure size. 10 11 This function takes an image in the form of a NumPy array and displays it using matplotlib. 12 If the image is 2D (grayscale), it will use a grayscale colormap for visualization. 13 It also provides an option to adjust the figure size via the `figsize` parameter. 14 15 Args: 16 image_np (numpy.ndarray): The image to be displayed. Can be either 2D (grayscale) or 3D (color) numpy array. 17 figsize (tuple, optional): The size of the figure (width, height). Default is (6, 6). 18 19 Raises: 20 ValueError: If the image provided is not a numpy array. 21 22 Returns: 23 None. The function directly displays the image. 24 """ 25 plt.figure(figsize=figsize) 26 27 # If the image is 2D (grayscale), use 'gray' colormap for a black & white mask 28 if image_np.ndim == 2: 29 plt.imshow(image_np, cmap="gray") 30 else: 31 plt.imshow(image_np) 32 33 # Remove axis and padding around the plot 34 plt.axis("off") 35 plt.subplots_adjust(left=0, right=1, top=1, bottom=0) 36 plt.show()
Displays an image using matplotlib, with optional customization of the figure size.
This function takes an image in the form of a NumPy array and displays it using matplotlib.
If the image is 2D (grayscale), it will use a grayscale colormap for visualization.
It also provides an option to adjust the figure size via the figsize parameter.
Arguments:
- image_np (numpy.ndarray): The image to be displayed. Can be either 2D (grayscale) or 3D (color) numpy array.
- figsize (tuple, optional): The size of the figure (width, height). Default is (6, 6).
Raises:
- ValueError: If the image provided is not a numpy array.
Returns:
None. The function directly displays the image.