0

At the moment I'm working with a ToF camera and I receive a distance image(matrix). I'm able to use Matlab watershed function to find all the valleys in the image.

Now I'm trying to use OpenCV watershed function, but it uses a RGB image as input. I tried to convert it to an RGB image (from grayscale to 255, followed by replicating to MxNx3-Matrix), but I'm getting wrong results.

resultOpenCV= cv.watershed(rgbImage,marker);

Is there some watershed function for depth images in OpenCV? Thanks.

Comparison Matlab watershed vs cv.watershed in Matlab: https://gist.github.com/amroamroamro/6423064ee20ad1a3d4de93ad7d68d8f5

mat file: https://www.dropbox.com/s/6whxuz111vu4ulp/watershedExample.mat?dl=0

Matteo B
  • 7
  • 4
  • Can you, please add a simplified example of your code, as well as a sample input image, if possible? – Dan Mašek Apr 01 '16 at 00:01
  • Oh, by image, i meant something containing the data. Like a grayscale PNG (use `cv2.imwrite`), or even a CSV file would do. Also, add the code that you use to make the RGB image. How do you create your markers and what are they for this input? Basically something we can run locally, and use to reproduce your problem. – Dan Mašek Apr 01 '16 at 00:45
  • @DanMašek https://www.dropbox.com/s/k1ce49n5tksmu5i/untitled.png?dl=0 I'm using Matlab with matrices, but I converted the matrix to intensity png now – Matteo B Apr 01 '16 at 01:16
  • By accident this is the 'raw' depth image, not the smoothed like in my OP, nevertheless, with correct markers shouldn't be a problem. – Matteo B Apr 01 '16 at 01:27
  • I've sorta mentioned this to you [elsewhere](https://github.com/kyamagu/mexopencv/issues/238#issuecomment-203062373); the [watershed](http://docs.opencv.org/3.1.0/d7/d1b/group__imgproc__misc.html#ga3267243e4d3f95165d55a618c65ac6e1) function in OpenCV usually takes as input an image to segment (along with markers), not the distance-transform of the image. The MATLAB [function](http://www.mathworks.com/help/images/ref/watershed.html) is different because it implements just the transform not the segmentation.. – Amro Apr 01 '16 at 11:07
  • you might wanna read these: http://blogs.mathworks.com/steve/2013/11/19/watershed-transform-question-from-tech-support/, http://cmm.ensmp.fr/~beucher/wtshed.html – Amro Apr 01 '16 at 11:07
  • To help out those who don't have access to MATLAB, here's a comparison between the two functions using the data posted above: https://gist.github.com/amroamroamro/6423064ee20ad1a3d4de93ad7d68d8f5 – Amro Apr 01 '16 at 11:41
  • @Amro I don't fully understand you, but are you saying that it will never work with cv.watershed? Ty for the comparison btw – Matteo B Apr 01 '16 at 14:46

0 Answers0