| 76 | return TransformFactory(name=str(self), apply_image=lambda img: self._impl(img)) |
| 77 | |
| 78 | def _impl(self, img): |
| 79 | img_shape = img.shape[:2] |
| 80 | assert self.background_shape[0] >= img_shape[0] and self.background_shape[1] >= img_shape[1] |
| 81 | |
| 82 | background = self.background_filler.fill( |
| 83 | self.background_shape, img) |
| 84 | y0 = int((self.background_shape[0] - img_shape[0]) * 0.5) |
| 85 | x0 = int((self.background_shape[1] - img_shape[1]) * 0.5) |
| 86 | background[y0:y0 + img_shape[0], x0:x0 + img_shape[1]] = img |
| 87 | return background |
| 88 | |
| 89 | |
| 90 | class RandomPaste(CenterPaste): |