:py:mod:`anomalib.data.utils.image` =================================== .. py:module:: anomalib.data.utils.image .. autoapi-nested-parse:: Image Utils. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: anomalib.data.utils.image.get_image_filenames anomalib.data.utils.image.duplicate_filename anomalib.data.utils.image.generate_output_image_filename anomalib.data.utils.image.read_image anomalib.data.utils.image.pad_nextpow2 .. py:function:: get_image_filenames(path: Union[str, pathlib.Path]) -> List[pathlib.Path] Get image filenames. :param path: Path to image or image-folder. :type path: Union[str, Path] :returns: List of image filenames :rtype: List[Path] .. py:function:: duplicate_filename(path: Union[str, pathlib.Path]) -> pathlib.Path Check and duplicate filename. This function checks the path and adds a suffix if it already exists on the file system. :param path: Input Path :type path: Union[str, Path] .. rubric:: Examples >>> path = Path("datasets/MVTec/bottle/test/broken_large/000.png") >>> path.exists() True If we pass this to ``duplicate_filename`` function we would get the following: >>> duplicate_filename(path) PosixPath('datasets/MVTec/bottle/test/broken_large/000_1.png') :returns: Duplicated output path. :rtype: Path .. py:function:: generate_output_image_filename(input_path: Union[str, pathlib.Path], output_path: Union[str, pathlib.Path]) -> pathlib.Path Generate an output filename to save the inference image. This function generates an output filaname by checking the input and output filenames. Input path is the input to infer, and output path is the path to save the output predictions specified by the user. The function expects ``input_path`` to always be a file, not a directory. ``output_path`` could be a filename or directory. If it is a filename, the function checks if the specified filename exists on the file system. If yes, the function calls ``duplicate_filename`` to duplicate the filename to avoid overwriting the existing file. If ``output_path`` is a directory, this function adds the parent and filenames of ``input_path`` to ``output_path``. :param input_path: Path to the input image to infer. :type input_path: Union[str, Path] :param output_path: Path to output to save the predictions. Could be a filename or a directory. :type output_path: Union[str, Path] .. rubric:: Examples >>> input_path = Path("datasets/MVTec/bottle/test/broken_large/000.png") >>> output_path = Path("datasets/MVTec/bottle/test/broken_large/000.png") >>> generate_output_image_filename(input_path, output_path) PosixPath('datasets/MVTec/bottle/test/broken_large/000_1.png') >>> input_path = Path("datasets/MVTec/bottle/test/broken_large/000.png") >>> output_path = Path("results/images") >>> generate_output_image_filename(input_path, output_path) PosixPath('results/images/broken_large/000.png') :raises ValueError: When the ``input_path`` is not a file. :returns: The output filename to save the output predictions from the inferencer. :rtype: Path .. py:function:: read_image(path: Union[str, pathlib.Path]) -> numpy.ndarray Read image from disk in RGB format. :param path: path to the image file :type path: str, Path .. rubric:: Example >>> image = read_image("test_image.jpg") :returns: image as numpy array .. py:function:: pad_nextpow2(batch: torch.Tensor) -> torch.Tensor Compute required padding from input size and return padded images. Finds the largest dimension and computes a square image of dimensions that are of the power of 2. In case the image dimension is odd, it returns the image with an extra padding on one side. :param batch: Input images :type batch: Tensor :returns: Padded batch :rtype: batch