Passed
Pull Request — master (#1)
by Konstantinos
01:08
created

artificial_artwork.image.image_factory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ImageFactory.from_disk() 0 4 1
1
import attr
2
from typing import Protocol, Any, Callable, List
3
from numpy.typing import NDArray
4
5
from .image_processor import ImageProcessor
6
from .image import Image
7
8
9
# Define type aliases
10
class ImageProtocol(Protocol):
11
    file_path: str
12
    matrix: NDArray
13
14
# define type alias for a callable that takes any number of arguments
15
ImageLoaderFunctionType = Callable[..., NDArray]
16
17
18
@attr.s
19
class ImageFactory:
20
    image_loader: ImageLoaderFunctionType = attr.ib()
21
    image_processor: ImageProcessor = attr.ib(default=attr.Factory(ImageProcessor))
22
23
    def from_disk(self, image_path: str, pipeline: List[Callable[[NDArray], NDArray]]=[], **kwargs) -> ImageProtocol:
24
        matrix = self.image_loader(image_path, **kwargs)
25
        matrix = self.image_processor.process(matrix, pipeline)
26
        return Image(image_path, matrix)
27