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