Skip to content

[Feature] ChanVese Segementation - #4160

Closed
dheer-prog wants to merge 30 commits into
opencv:5.xfrom
dheer-prog:chanvese
Closed

dheer-prog wants to merge 30 commits into
opencv:5.xfrom
dheer-prog:chanvese

Conversation

@dheer-prog

@dheer-prog dheer-prog commented Jun 22, 2026 •

Copy link
Copy Markdown

This is an implementation of the Chan Vese Algorithm based on the following paper:-
T. F. Chan and L. A. Vese, "Active contours without edges," IEEE Transactions on Image Processing, vol. 10, no. 2, pp. 266-277, Feb. 2001

Currently this implementation only outputs a binary image depending upon the segmented region, I'll soon add a way to generate contours using this method, as it ensures that the contours are smooth and not jaggy as that are formed by edge based method like for example Canny Edge detectors

Issue requesting this feature:-#4141

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

rebase test

basic chan vese

fixed

t

broken chan vese

Added tests

Added Documentation
@dheer-prog

Copy link
Copy Markdown
Author

Hello @asmorkalov , I know the formatting of segmentation.hpp is incorrect, I have created a pull request addressing the issue:- #4157
Once that is merged I'll just rebase this pr and both the Statistical Region Merging pr(#4156) will contain the correct formatting,

@dheer-prog

Copy link
Copy Markdown
Author

Also I was able to find an C implementation of this and hence was to able to add a chanvese_expected.png in test_chanvese.cpp for comparision
chanvese_input
chanvese_output

@dheer-prog

dheer-prog commented Jun 24, 2026 •

Copy link
Copy Markdown
Author

Hello @quink-black @asmorkalov , could you please review this pr

xiaoyuan1021 and others added 5 commits July 2, 2026 09:27
line_descriptor: fix heap buffer overflow in EdgeDrawing()  EdgeDrawing() allocates edge pixel buffers of size pixelNum/5, but writes without checking bounds. When the image has high edge density, offsetPFirst/offsetPSecond exceed the buffer, corrupting the heap.  Add bounds checks before each write to prevent overflow. This fixes the crash reported in opencv#1999.
fix heap buffer overflow in EdgeDrawing()
PCTSignatures_Impl::getSampleCount() called mSampler->getGrayscaleBits()
instead of mSampler->getSampleCount(), so it always returned the
grayscale bit depth (default 4) instead of the actual number of
sampling points passed to create().

PCTSampler_Impl::getSampleCount() itself was already correct, returning
mInitSamplingPoints.size(), so only the accessor delegation needed fixing.
…raticFormDistances

Parallel_computeSQFDs::operator() indexed mImageSignatures (a pointer to
a std::vector<Mat>) as mImageSignatures[i] instead of dereferencing the
vector first, i.e. (*mImageSignatures)[i]. This happened to work for
i == 0 (mImageSignatures[0] is equivalent to *mImageSignatures), but for
i >= 1 it read past the pointed-to vector as unallocated memory,
producing undefined behavior (typically a spurious "Signature ID: N is
empty!" exception once imageSignatures has 2 or more elements).
@dheer-prog

Copy link
Copy Markdown
Author

@asmorkalov have you had a chance to review this

DmytroHilei and others added 2 commits July 12, 2026 10:53
…tency-fix

cudastereo: fix StereoSGM consistency check launch bounds opencv#4165

Extra: opencv/opencv_extra#1392

check_consistency previously launched dim3(width/16, height/16); integer division floored away a right/bottom strip up to 15 px wide whenever an image dimension was not a multiple of 16, leaving those pixels never visited by check_consistency_kernel. They kept WTA's output and skipped L/R invalidation. On the common 1920x1080 case (1080 mod 16 = 8) this affected the bottom 8 rows of every frame.

Switch the grid to cudev::divUp and add an in-kernel bounds-check so the now-overhanging threads return cleanly. Add a regression test (StereoSGM_NonAligned) in test_stereo.cpp that feeds unrelated random images of non-aligned size into cv::cuda::StereoSGM::compute and verifies the previously-uncovered strip is touched by check_consistency.

Also fix a latent typo in store_uint8_vector<2u> (second lane was ptr[0] instead of ptr[1], breaking the dest[i] = ptr[i] contract held by the <1u>, <4u>, <8u>, <16u> specializations). The <2u> specialization is unreachable in current code; included as defensive hygiene against a future DP_BLOCK_SIZE = 2u variant.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
@dheer-prog
dheer-prog marked this pull request as draft July 13, 2026 15:15
@dheer-prog
dheer-prog marked this pull request as ready for review July 13, 2026 15:16
asmorkalov and others added 16 commits July 14, 2026 12:52
…ecount

xfeatures2d: fix PCTSignatures::getSampleCount() copy-paste bug
…read

xfeatures2d: fix out-of-bounds read in PCTSignaturesSQFD::computeQuadraticFormDistances
viz: Add iostream include to precomp.hpp
Remove deprecated CommaInitializer API
Calling a function through a function pointer with a mismatched signature is
undefined behavior in C/C++ and causes Clang Control Flow Integrity
to trap with `SIGILL` (`ud1`) at indirect call sites.
Fix function pointer signature mismatches
Use [[fallthrough]] instead of comments where needed
vrabaud and others added 6 commits September 24, 2026 11:00
Remove references to C++ < 17 and older compiler versions.
rebase test

basic chan vese

fixed

t

broken chan vese

Added tests

Added Documentation
@dheer-prog dheer-prog closed this Oct 4, 2026
@dheer-prog

Copy link
Copy Markdown
Author

Made some errors now there are many pr's in this will open new one

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.

8 participants