Segment sky from an image file, returning continuous non-sky confidence in [0, 1].
(
image_path: str,
skyseg_session,
output_path: Optional[str] = None,
)
| 232 | |
| 233 | |
| 234 | def segment_sky( |
| 235 | image_path: str, |
| 236 | skyseg_session, |
| 237 | output_path: Optional[str] = None, |
| 238 | ) -> np.ndarray: |
| 239 | """Segment sky from an image file, returning continuous non-sky confidence in [0, 1].""" |
| 240 | image = cv2.imread(image_path) |
| 241 | if image is None: |
| 242 | raise ValueError(f"Failed to read image: {image_path}") |
| 243 | |
| 244 | result_map = run_skyseg(skyseg_session, _SKYSEG_INPUT_SIZE, image) |
| 245 | result_map = cv2.resize(result_map, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_LINEAR) |
| 246 | mask = _result_map_to_non_sky_conf(result_map) |
| 247 | |
| 248 | if output_path is not None: |
| 249 | output_dir = os.path.dirname(output_path) |
| 250 | if output_dir: |
| 251 | os.makedirs(output_dir, exist_ok=True) |
| 252 | cv2.imwrite(output_path, _mask_to_uint8(mask)) |
| 253 | |
| 254 | return mask |
| 255 | |
| 256 | |
| 257 | # --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected