| Total Complexity | 1 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |