ml.images.io
module ml.images.io
The io module provides standard helper functions to load images from disk
#
Global Variables- IMREAD_COLOR
load_image_from_disk
#
function load_image_from_disk( path: str, image_size=None, convert_to_grey: bool = False, keep_3d_shape=False) โ <built-in function array>
Loads an image from file, applying preformatting
Args:
- `path` (str): The filename of the image to load
- `image_size` (tuple): The image size can be passed as tuple (W, H) or as int (W=H)
- `convert_to_grey` (bool): This would reduce the size (and shape) of the image in making it a greyscale
- `keep_3d_shape` (bool): Only used when convert_to_grey is true. Will keep the images in shape (H,W,1) in that case
Returns:
- `np.array`: A numpy array that represents the image
load_images
#
function load_images( path: str, image_size=None, max_images: int = -1, valid_extensions: <built-in function array> = ['.jpg', '.jpeg', '.gif', '.png'], convert_to_grey: bool = False, keep_3d_shape=False) โ <built-in function array>
Loads the images from a specific folder
Args:
- `path` (str): The path or folder name to load images from. This can be a relative or fully qualified path
- `image_size` (tuple): The image size can be passed as tuple (W, H) or as int (W=H)
- `max_images` (int): The maximum amount of images to load from the folder. If 0 or smaller, all images will be returned
- `valid_extensions` (np.array): The file extensions that should be filtered. Defaults to jpg, jpeg, gif and png
- `convert_to_grey` (bool): This would reduce the size (and shape) of the image in making it a greyscale
- `keep_3d_shape` (bool): Only used when convert_to_grey is true. Will keep the images in shape (H,W,1) in that case
Returns:
- `np.array`: A numpy array that contains all selected images represented as np.array
load_image_from_url
#
function load_image_from_url( image_url: str, http_headers: dict = None, image_size=None, convert_to_grey: bool = False, keep_3d_shape=False, cache_location: str = None, file_name: str = None, force_download: bool = False) โ <built-in function array>
Loads an image from a given url, applying preformatting and supporting file caching
Args:
- `image_url` (str): The url to download the image.
- `http_headers` (dict): The http headers to pass with the request as a dictionary
- `image_size` (tuple): The image size can be passed as tuple (W, H) or as int (W=H)
- `convert_to_grey` (bool): This would reduce the size (and shape) of the image in making it a greyscale
- `keep_3d_shape` (bool): Only used when convert_to_grey is true. Will keep the images in shape (H,W,1) in that case
- `cache_location` (str): When provided, the image will be cached to this folder location on disk
- `file_name` (str): The file name of the image to be cached
- `force_download` (bool): When true, the image will always be redownloaded and not retrieved from cache
Returns:
- `np.array`: A numpy array that represents the image
load_images_from_dataframe
#
function load_images_from_dataframe( df: DataFrame, image_column_name: str, target_column_name: str, image_size=None, max_images: int = -1, target_as_image: bool = False, convert_to_grey: bool = False, keep_3d_shape=False) โ (<built-in function array>, <built-in function array>)
Loads a set images from disk, based on the file name in a Data Frame. And returns a related array (target) that can contain values from another column, or also images from disk
Args:
- `df` (pd.DataFrame): the DataFrame, containing the references to the image
- `image_column_name` (str): The name of the column that contains the image reference
- `target_column_name` (str): The name of the column that contains the related target data
- `image_size` (tuple): The image size can be passed as tuple (W, H) or as int (W=H)
- `max_images` (int): The maximum amount of images to load from the folder. If 0 or smaller, all images will be returned
- `target_as_image` (bool): Defines if the target column contains file names that should be loaded as image. If not, the column data will be used in the target array
- `convert_to_grey` (bool): This would reduce the size (and shape) of the image in making it a greyscale
- `keep_3d_shape` (bool): Only used when convert_to_grey is true. Will keep the images in shape (H,W,1) in that case
Returns: a tuple with the following objects:
- `np.array`: A numpy array that contains all selected images represented as np.array
- `np.array`: A numpy array that represents all targets that were asked
This file was automatically generated via lazydocs.