(self, img, **params)
| 100 | self.mag = mag |
| 101 | |
| 102 | def apply(self, img, **params): |
| 103 | img = Image.fromarray(img.astype(np.uint8)) |
| 104 | w, h = img.size |
| 105 | c = [(1.5, 2), (2., 2), (2.5, 1.7)] |
| 106 | if self.mag < 0 or self.mag >= len(c): |
| 107 | index = self.rng.integers(0, len(c)) |
| 108 | else: |
| 109 | index = self.mag |
| 110 | c = c[index] |
| 111 | n_channels = len(img.getbands()) |
| 112 | isgray = n_channels == 1 |
| 113 | img = np.asarray(img) / 255. |
| 114 | max_val = img.max() |
| 115 | max_size = 2**math.ceil(math.log2(max(w, h)) + 1) |
| 116 | fog = c[0] * plasma_fractal(mapsize=max_size, |
| 117 | wibbledecay=c[1], |
| 118 | rng=self.rng)[:h, :w][..., np.newaxis] |
| 119 | if isgray: |
| 120 | fog = np.squeeze(fog) |
| 121 | else: |
| 122 | fog = np.repeat(fog, 3, axis=2) |
| 123 | img += fog |
| 124 | img = np.clip(img * max_val / (max_val + c[0]), 0, 1) * 255 |
| 125 | return img.astype(np.uint8) |
| 126 | |
| 127 | class Frost(A.ImageOnlyTransform): |
| 128 |
no test coverage detected