Source code for compimg.exceptions
"""compimg exceptions module"""
import numpy as np
from typing import Sequence
[docs]class DifferentShapesError(Exception):
def __init__(self, shape1: Sequence[int], shape2: Sequence[int]):
super().__init__(f"Images have different shapes: {shape1} != {shape2}.")
[docs]class DifferentDTypesError(Exception):
def __init__(self, dtype1: np.dtype, dtype2: np.dtype):
super().__init__(
f"Images have different dtypes: {dtype1.name} != {dtype2.name}."
)
[docs]class NegativePadAmountError(Exception):
def __init__(self, amount):
super().__init__(f"Pad cannot be negative value like {amount}.")
[docs]class KernelBiggerThanImageError(Exception):
def __init__(self, kernel_shape: Sequence[int], image_shape: Sequence[int]):
super().__init__(
f"\nKernel used in convolution must be bigger that image itself."
f"Kernel shape = {kernel_shape}, Image shape = {image_shape}"
)
[docs]class KernelShapeNotOddError(Exception):
def __init__(self, kernel_shape: Sequence[int]):
super().__init__(
f"\nKernel used in convolution must be of odd shape. "
f"Kernel shape = {kernel_shape}, rows and columns must be odd."
)
[docs]class KernelNot2DArray(Exception):
def __init__(self, dims: int):
super().__init__(f"\nKernel must be 2D numpy array, not {dims}D.")