Skip to content

disk_operations

Disk

Bases: DiskInterface

Save or load images to and from the disk.

Source code in src/artificial_artwork/disk_operations.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Disk(DiskInterface):
    """Save or load images to and from the disk."""

    @staticmethod
    def save_image(image: NDArray, file_path: str, save_format=None) -> None:
        """Save a numpy ndarray into a file on the disk.

        Args:
            image (NDArray): the image to save into a file
            file_path (str): the path (on the disk) of the file
        """
        imageio.imsave(file_path, image, format=save_format)

    @staticmethod
    def load_image(file_path: str) -> NDArray:
        """Load an image as numpy ndarray from a file on the disk.

        Args:
            file_path (str): the path (on the disk) of the file

        Returns:
            NDArray: the image as numpy ndarray
        """
        return imageio.imread(file_path)

load_image(file_path) staticmethod

Load an image as numpy ndarray from a file on the disk.

Parameters:

Name Type Description Default
file_path str

the path (on the disk) of the file

required

Returns:

Name Type Description
NDArray NDArray

the image as numpy ndarray

Source code in src/artificial_artwork/disk_operations.py
20
21
22
23
24
25
26
27
28
29
30
@staticmethod
def load_image(file_path: str) -> NDArray:
    """Load an image as numpy ndarray from a file on the disk.

    Args:
        file_path (str): the path (on the disk) of the file

    Returns:
        NDArray: the image as numpy ndarray
    """
    return imageio.imread(file_path)

save_image(image, file_path, save_format=None) staticmethod

Save a numpy ndarray into a file on the disk.

Parameters:

Name Type Description Default
image NDArray

the image to save into a file

required
file_path str

the path (on the disk) of the file

required
Source code in src/artificial_artwork/disk_operations.py
10
11
12
13
14
15
16
17
18
@staticmethod
def save_image(image: NDArray, file_path: str, save_format=None) -> None:
    """Save a numpy ndarray into a file on the disk.

    Args:
        image (NDArray): the image to save into a file
        file_path (str): the path (on the disk) of the file
    """
    imageio.imsave(file_path, image, format=save_format)