kyamagu / mexopencv

Collection and a development kit of matlab mex functions for OpenCV library
http://kyamagu.github.io/mexopencv
Other
659 stars 318 forks source link

cv.watershed not working like expected #238

Open matbee opened 8 years ago

matbee commented 8 years ago

Hey,

I succesfully used the watershed function from Matlab, but OpenCV variant is not working. I'm not sure if this is mexopencv related, maybe I misunderstood the watershed algorithm in OpenCV.

I'm using following int8 depth image: image description

because openCV using RGB image format, I replicated these values in a MxNx3-matrix. As marker I have an int32 matrix where I pointed every local minimum (5 in total), image description

By using following function

resultOpenCV= cv.watershed(rgbImage,marker);

The segmented matrix looks like this: image description

In Matlab using following function (even without markers)

resultMatlab= watershed(rgbImage(:,:,1));

This is the correct result: image description

Where am I wrong?

Thank you

amroamroamro commented 8 years ago

This is really a question for OpenCV Q&A or Stack Overflow... The mexopencv code for the watershed function is doing very little, other than converting between OpenCV and MATLAB arrays, and calling the C++ function: https://github.com/kyamagu/mexopencv/blob/master/src/%2Bcv/watershed.cpp

Ultimately these two functions are different implementations of the algorithm; MATLAB watershed implements the watershed transform, while OpenCV cv::watershed implements an interactive marker-based watershed segmentation.