(image)
| 58 | |
| 59 | |
| 60 | def segment_sky(image): |
| 61 | import cv2 |
| 62 | from scipy import ndimage |
| 63 | |
| 64 | # Convert to HSV |
| 65 | image = to_numpy(image) |
| 66 | if np.issubdtype(image.dtype, np.floating): |
| 67 | image = np.uint8(255 * image.clip(min=0, max=1)) |
| 68 | hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) |
| 69 | |
| 70 | # Define range for blue color and create mask |
| 71 | lower_blue = np.array([0, 0, 100]) |
| 72 | upper_blue = np.array([30, 255, 255]) |
| 73 | mask = cv2.inRange(hsv, lower_blue, upper_blue).view(bool) |
| 74 | |
| 75 | # add luminous gray |
| 76 | mask |= (hsv[:, :, 1] < 10) & (hsv[:, :, 2] > 150) |
| 77 | mask |= (hsv[:, :, 1] < 30) & (hsv[:, :, 2] > 180) |
| 78 | mask |= (hsv[:, :, 1] < 50) & (hsv[:, :, 2] > 220) |
| 79 | |
| 80 | # Morphological operations |
| 81 | kernel = np.ones((5, 5), np.uint8) |
| 82 | mask2 = ndimage.binary_opening(mask, structure=kernel) |
| 83 | |
| 84 | # keep only largest CC |
| 85 | _, labels, stats, _ = cv2.connectedComponentsWithStats( |
| 86 | mask2.view(np.uint8), connectivity=8 |
| 87 | ) |
| 88 | cc_sizes = stats[1:, cv2.CC_STAT_AREA] |
| 89 | order = cc_sizes.argsort()[::-1] # bigger first |
| 90 | i = 0 |
| 91 | selection = [] |
| 92 | while i < len(order) and cc_sizes[order[i]] > cc_sizes[order[0]] / 2: |
| 93 | selection.append(1 + order[i]) |
| 94 | i += 1 |
| 95 | mask3 = np.in1d(labels, selection).reshape(labels.shape) |
| 96 | |
| 97 | # Apply mask |
| 98 | return torch.from_numpy(mask3) |
| 99 | |
| 100 | |
| 101 | def convert_scene_output_to_glb( |
nothing calls this directly
no test coverage detected