[summary] Class representing a motion blur kernel of a given intensity. [description] Keyword Arguments: size {tuple} -- Size of the kernel in px times px (default: {(100, 100)}) intensity {float} -- Float between 0 and 1. Intensity of th
| 50 | |
| 51 | |
| 52 | class Kernel(object): |
| 53 | """[summary] |
| 54 | Class representing a motion blur kernel of a given intensity. |
| 55 | |
| 56 | [description] |
| 57 | Keyword Arguments: |
| 58 | size {tuple} -- Size of the kernel in px times px |
| 59 | (default: {(100, 100)}) |
| 60 | |
| 61 | intensity {float} -- Float between 0 and 1. |
| 62 | Intensity of the motion blur. |
| 63 | |
| 64 | : 0 means linear motion blur and 1 is a highly non linear |
| 65 | and often convex motion blur path. (default: {0}) |
| 66 | |
| 67 | Attribute: |
| 68 | kernelMatrix -- Numpy matrix of the kernel of given intensity |
| 69 | |
| 70 | Properties: |
| 71 | applyTo -- Applies kernel to image |
| 72 | (pass as path, pillow image or np array) |
| 73 | |
| 74 | Raises: |
| 75 | ValueError |
| 76 | """ |
| 77 | |
| 78 | def __init__(self, size: tuple = (100, 100), intensity: float=0): |
| 79 | |
| 80 | # checking if size is correctly given |
| 81 | if not isinstance(size, tuple): |
| 82 | raise ValueError("Size must be TUPLE of 2 positive integers") |
| 83 | elif len(size) != 2 or type(size[0]) != type(size[1]) != int: |
| 84 | raise ValueError("Size must be tuple of 2 positive INTEGERS") |
| 85 | elif size[0] < 0 or size[1] < 0: |
| 86 | raise ValueError("Size must be tuple of 2 POSITIVE integers") |
| 87 | |
| 88 | # check if intensity is float (int) between 0 and 1 |
| 89 | if type(intensity) not in [int, float, np.float32, np.float64]: |
| 90 | raise ValueError("Intensity must be a number between 0 and 1") |
| 91 | elif intensity < 0 or intensity > 1: |
| 92 | raise ValueError("Intensity must be a number between 0 and 1") |
| 93 | |
| 94 | # saving args |
| 95 | self.SIZE = size |
| 96 | self.INTENSITY = intensity |
| 97 | |
| 98 | # deriving quantities |
| 99 | |
| 100 | # we super size first and then downscale at the end for better |
| 101 | # anti-aliasing |
| 102 | self.SIZEx2 = tuple([2 * i for i in size]) |
| 103 | self.x, self.y = self.SIZEx2 |
| 104 | |
| 105 | # getting length of kernel diagonal |
| 106 | self.DIAGONAL = (self.x**2 + self.y**2)**0.5 |
| 107 | |
| 108 | # flag to see if kernel has been calculated already |
| 109 | self.kernel_is_generated = False |
no outgoing calls
no test coverage detected