(blank_blocks_y, blank_blocks_x, image)
| 89 | |
| 90 | |
| 91 | def remove_blocks(blank_blocks_y, blank_blocks_x, image): |
| 92 | mask = np.ones(image.shape[:2], dtype=bool) |
| 93 | for start, end in blank_blocks_y: |
| 94 | mask[:, start:end] = False |
| 95 | for start, end in blank_blocks_x: |
| 96 | mask[start:end, :] = False |
| 97 | |
| 98 | # Extract non-black regions |
| 99 | if len(image.shape) == 2: # Grayscale |
| 100 | rows = np.any(mask, axis=1) |
| 101 | cols = np.any(mask, axis=0) |
| 102 | return image[rows][:, cols] |
| 103 | else: # Color |
| 104 | rows = np.any(mask, axis=1) |
| 105 | cols = np.any(mask, axis=0) |
| 106 | return image[rows][:, cols] |
| 107 | |
| 108 | |
| 109 | # crop & split fullpage screenshot to multiple small images |
no outgoing calls
no test coverage detected