ximgproc: EdgeDrawing must not modify the caller's input when Sigma < 1.0 - #4206
Open
purehol wants to merge 1 commit into
Open
ximgproc: EdgeDrawing must not modify the caller's input when Sigma < 1.0#4206purehol wants to merge 1 commit into
purehol wants to merge 1 commit into
Conversation
… 1.0 When Params::Sigma < 1.0, detectEdges() set `smoothImage = srcImage`, aliasing the caller's input Mat. detectEllipses() then runs an in-place GaussianBlur into smoothImage (the PFmode path in detectEdges() does the same), silently overwriting the user's input image and any later reads of it. Clone the image so the input stays read-only, matching the reference implementation ED_Lib. Adds a regression test that fails before this change (1916 pixels of the input were modified) and passes after it.
purehol
marked this pull request as ready for review
September 2, 2026 15:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
When
Params::Sigma < 1.0,detectEdges()setsmoothImage = srcImage, aliasingthe caller's input Mat.
detectEllipses()then runs an in-placeGaussianBlurinto
smoothImage(the PFmode path indetectEdges()does the same), silentlyoverwriting the user's input image and any later reads of it.
Fix
Clone the image so the input stays read-only, matching the reference implementation
ED_Lib (which always blurs into a separately allocated buffer). Cost is one
width*heightcopy whenSigma < 1.0; correctness takes priority.Verification
Added
TEST_F(ximgproc_ED, detectEllipsesDoesNotModifyInput): withSigma = 0.0it asserts the input Mat is unchanged after
detectEdges()+detectEllipses().Fails before this change (1916 input pixels modified) and passes after it;
existing
*ED*tests still pass.Fixes #4203