Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Adds user-controllable dilation to expand the foreground mask, preventing edge clipping during movement. Addresses the issue where tight background removal causes parts of the subject to be cut off, particularly useful when combining with chroma key on small green screens.

Implementation

  • New slider: "Mask Expansion" (0.0-1.0) in Advanced settings section, scales to 1-11 dilation iterations
  • UI placement: Located directly in Advanced settings for easy access (not buried in threshold group)
  • Processing order: Applied after mask smoothing, before feathering for clean expansion
  • Default: 0.0 (no expansion, preserves existing behavior)

Technical Details

// Expand the mask to create a larger "safe" area around the detected person
if (tf->maskExpansion > 0.0) {
    // Scale from 0.0-1.0 to 1-11 dilation iterations
    int expansion_iterations = (int)(1 + 10 * tf->maskExpansion);
    cv::dilate(backgroundMask, backgroundMask, cv::Mat(), cv::Point(-1, -1),
               expansion_iterations);
}

Uses OpenCV's morphological dilation as suggested by @umireon. Also adds missing localization string for "TemporalSmoothFactor" found during implementation.

The slider is hidden by default (behind Advanced settings checkbox) to keep the UI simple for most users, while remaining easily accessible for advanced users who need fine control over mask expansion.

Original prompt

This section details on the original issue you should resolve

<issue_title>Larger "safe" area around detected person</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.

This plugin is great if you have a small green screen, because you can run it first, then run a Chroma Key, removing the need to crop your camera. However, the edge around the individual is too aggressive, and there's no way to "expand" the viewable area so that movement doesn't get wiped behind the cut.

Describe the solution you'd like

The ability to "expand" the uncropped area via a slider, basically putting more of the background visible around the subject.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@umireon Hello Fmstrat,

My name is Kaito, and I'm a former contributor to this project.

I have recently developed a new plugin called "OBS Background Removal Lite," which offers similar functionality to this one. For anyone interested in an alternative, I would be grateful if you could give it a try.

Any feedback would be greatly appreciated!

You can find the plugin here:
https://github.com/kaito-tokyo/obs-backgroundremoval-lite#readme

Thank you.</comment_new>
<comment_new>@umireon
This can be done by dilation filter and OpenCV has this filter.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add slider to expand safe area around detected person Add mask expansion slider to enlarge safe area around detected person Nov 7, 2025
Copilot AI requested a review from umireon November 7, 2025 16:54
@umireon
Copy link
Collaborator

umireon commented Nov 7, 2025

@royshil Do you think this feature is good?

@royshil
Copy link
Owner

royshil commented Nov 7, 2025

Yea it seems like a useful tool
But I'd hide it in the settings in the "advanced" settings section
Since we want to keep it simple for most people

@umireon
Copy link
Collaborator

umireon commented Nov 7, 2025

Proposed in #637. I'll refine this impl and make this PR ready.

@umireon
Copy link
Collaborator

umireon commented Nov 10, 2025

@copilot Yea it seems like a useful tool
But I'd hide it in the settings in the "advanced" settings section
Since we want to keep it simple for most people

Copy link
Contributor Author

Copilot AI commented Nov 10, 2025

@copilot Yea it seems like a useful tool
But I'd hide it in the settings in the "advanced" settings section
Since we want to keep it simple for most people

Done! Moved the Mask Expansion slider out of the threshold group and into the main advanced settings section. Now users only need to enable "Advanced settings" to access it, rather than having to enable both "Advanced settings" and "Enable threshold". (commit 6fa964e)

@umireon umireon added this to the 1.3.3 milestone Nov 10, 2025
@umireon
Copy link
Collaborator

umireon commented Nov 10, 2025

@royshil

How about this?

2025-11-11.2.27.51.mov.mp4

@umireon umireon requested a review from royshil November 10, 2025 17:29
Copy link
Owner

@royshil royshil left a comment

Choose a reason for hiding this comment

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

I think it's a cool little addition
Merge at will

@umireon umireon marked this pull request as ready for review November 10, 2025 18:20
@umireon umireon merged commit 9bf3303 into main Nov 10, 2025
8 checks passed
@umireon umireon deleted the copilot/expand-safe-area-slider branch November 10, 2025 23:29
sobalap pushed a commit to sobalap/obs-backgroundremoval that referenced this pull request Jan 7, 2026
…royshil#670)

* Initial plan

* Add mask expansion feature to enlarge safe area around detected person

Co-authored-by: umireon <[email protected]>

* Address code review feedback: add constant for max expansion iterations

Co-authored-by: umireon <[email protected]>

* Follow codebase pattern: use inline magic numbers with clear comments

Co-authored-by: umireon <[email protected]>

* Move mask expansion slider to advanced settings (not in threshold group)

Co-authored-by: umireon <[email protected]>

* Update background-filter.cpp

* Update background-filter.cpp

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: umireon <[email protected]>
Co-authored-by: Kaito Udagawa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Larger "safe" area around detected person

3 participants