MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / segment_sky

Function segment_sky

benchmark/models/loger/utils/visual_util.py:618–646  ·  view source on GitHub ↗

Segments sky from an image using an ONNX model. Thanks for the great model provided by https://github.com/xiongzhu666/Sky-Segmentation-and-Post-processing Args: image_path: Path to input image onnx_session: ONNX runtime session with loaded model mask_filename: P

(image_path, onnx_session, mask_filename=None)

Source from the content-addressed store, hash-verified

616
617
618def segment_sky(image_path, onnx_session, mask_filename=None):
619 """
620 Segments sky from an image using an ONNX model.
621 Thanks for the great model provided by https://github.com/xiongzhu666/Sky-Segmentation-and-Post-processing
622
623 Args:
624 image_path: Path to input image
625 onnx_session: ONNX runtime session with loaded model
626 mask_filename: Path to save the output mask
627
628 Returns:
629 np.ndarray: Binary mask where 255 indicates non-sky regions
630 """
631
632 assert mask_filename is not None
633 image = cv2.imread(image_path)
634
635 result_map = run_skyseg(onnx_session, [320, 320], image)
636 # resize the result_map to the original image size
637 result_map_original = cv2.resize(result_map, (image.shape[1], image.shape[0]))
638
639 # Fix: Invert the mask so that 255 = non-sky, 0 = sky
640 # The model outputs low values for sky, high values for non-sky
641 output_mask = np.zeros_like(result_map_original)
642 output_mask[result_map_original < 32] = 255 # Use threshold of 32
643
644 os.makedirs(os.path.dirname(mask_filename), exist_ok=True)
645 cv2.imwrite(mask_filename, output_mask)
646 return output_mask
647
648
649def run_skyseg(onnx_session, input_size, image):

Callers 2

apply_sky_segmentationFunction · 0.90
predictions_to_glbFunction · 0.70

Calls 2

run_skysegFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected