segrails.pipeline.postprocess¶
Post-processing pipeline step.
Wraps _PostProcessor to convert an inference mask into structured track detections (center points, directions, IoU scores) using Hough lines and contour analysis.
Classes¶
Run post-processing on a segmentation mask to extract rail track detections. |
Module Contents¶
- class segrails.pipeline.postprocess.PostprocessStep(config: altametris.segrails.config.SegrailsConfig)¶
Run post-processing on a segmentation mask to extract rail track detections.
Wraps _PostProcessor. All detection parameters are read from SegrailsConfig.
- Parameters:
config – SegrailsConfig instance — provides inference_image_size and all detection_* parameters.
Example
>>> step = PostprocessStep(config) >>> result = step.run(image_np, mask, geotransform, filename="tile_001") >>> print(result.n_tracks)
- _config¶
- _postprocessor¶
- run(image: numpy.typing.NDArray[numpy.uint8], mask: numpy.typing.NDArray[numpy.uint8], geotransform: altametris.geo3d.rasters.types.GeoTransform, output_dir: pathlib.Path | None = None, filename: str = 'detection') altametris.segrails.result.SegrailsPrediction¶
Extract rail detections from a segmentation mask.
- Parameters:
image – RGB raster image as uint8 ndarray of shape
(H, W, 3), already resized toinference_image_size(as returned byInferenceStep.predict()). Passed directly to avoid re-reading the raster file that was already opened during inference.mask – Binary segmentation mask of shape (H, W) with dtype uint8, as returned by InferenceStep.predict().
geotransform – GeoTransform from RasterStep.generate(), used to map pixel coordinates to geographic coordinates.
output_dir – Optional directory for saving the detection JSON and debug images. Created if it does not exist.
filename – Base name for output files (no extension). Defaults to
"detection".
- Returns:
SegrailsPrediction with n_tracks, valid_tracks, crossings, total_missed_detections, total_low_detections and enriched tracks list.
- _format_predictions(raw: dict) altametris.segrails.result.SegrailsPrediction¶
Build SegrailsPrediction from raw _PostProcessor output in a single pass.
Enriches each track dict with
low_detections,missed_detectionsandoverall_iou. Usesdetection_iou_thresholdfrom config.- Parameters:
raw – Raw dict from _PostProcessor.run() with a
"tracks"key.- Returns:
SegrailsPrediction with all counters populated.