Skip to content

fix: output segmentation mask#50

Merged
ktro2828 merged 2 commits intomainfrom
fix/segmentation/output-mask
Sep 27, 2025
Merged

fix: output segmentation mask#50
ktro2828 merged 2 commits intomainfrom
fix/segmentation/output-mask

Conversation

@ktro2828
Copy link
Copy Markdown
Owner

Description

This PR tackles the issue #3.

This pull request improves the accuracy and visual quality of 2D semantic segmentation results by refining how segmentation masks are post-processed and visualized. The main changes ensure that segmentation masks are properly scaled and aligned with the original images, and that the visualization overlay is more consistent and visually clear.

Semantic segmentation mask post-processing:

  • The segmentation mask is now resized to match the original image size after correcting for any letterboxing and scaling, ensuring pixel-perfect alignment between the mask and the input image. This is done by extracting the valid region from the model output and resizing it back to the original dimensions using nearest neighbor interpolation to preserve class labels.
  • The OpenCV image processing header (opencv2/imgproc.hpp) was added to support the resizing operations.

Visualization improvements:

  • The visualizer now checks if the input image and segmentation mask sizes match, and resizes the mask if needed to ensure consistent overlay.
  • The color mask is converted from BGR to RGB for consistency with the input image, and the overlay blending ratios have been adjusted for better clarity, with the input image weighted more heavily than the mask.

How was this PR tested?

ros2 launch pidnet pidnet.launch.xml input/image:=/nuscenes/CAM_FRONT/image
Screencast.from.09-28-2025.08.36.22.AM.webm

Notes for reviewers

None.

Effects on system behavior

None.

Copilot AI review requested due to automatic review settings September 27, 2025 23:43
@ktro2828 ktro2828 added the bug Something isn't working label Sep 27, 2025
@ktro2828 ktro2828 requested review from Copilot and removed request for Copilot September 27, 2025 23:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes semantic segmentation mask output to ensure proper alignment with original images and improved visualization quality. The changes address letterbox scaling issues where masks were not correctly resized to match input image dimensions.

  • Adds post-processing to resize segmentation masks back to original image dimensions after correcting for letterbox scaling
  • Improves visualization by ensuring mask and image size consistency and adjusting color conversion and blending ratios
  • Adds bounds checking for class IDs to prevent invalid values

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
mmros/src/detector/semantic_segmenter2d.cpp Implements proper mask resizing logic to handle letterbox scaling and restore original image dimensions
mmrviz/src/visualizer/segmentation2d_visualizer.cpp Adds size validation and improves color conversion/blending for better visualization quality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread mmros/src/detector/semantic_segmenter2d.cpp Outdated
Comment thread mmros/src/detector/semantic_segmenter2d.cpp Outdated
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 force-pushed the fix/segmentation/output-mask branch from ebf47a5 to 30c9300 Compare September 27, 2025 23:55
@ktro2828 ktro2828 linked an issue Sep 27, 2025 that may be closed by this pull request
@ktro2828 ktro2828 merged commit 4753af7 into main Sep 27, 2025
1 check failed
@ktro2828 ktro2828 deleted the fix/segmentation/output-mask branch September 27, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] segmentation result is shifted

2 participants