Watershed... (am I getting the concept wrong?)
Hello and thank you always for your help. I would appreciate if you guys can give me your thoughts on watersheding. This time I will explain my problem with images.
The background
Some time ago, I studied some computer vision. (That was before learning OpenCV). While doing that, I learned the concept of watersheding. Now,as I read opencv watershed documentation, it seems to me that the concept is a bit different (for example there is no concept of "markers") from what I learned so I come to you, to see how can I use opencv to implement the concepts I learned before using OpenCV
The problem
Say I have the following image:(The image might come from say-segmentation, following by separating areas not connected to each other)
You can see that to the human eye there are 6 elements, but so far in the image we can see four clearly separated elements (the three on the right are still considered one) Now, please don't tell me to open them so as to separate them. First, opening has some undesirable results and I want to apply this solutions for cases where even opening does not work.
The goal
To separate those elements and get the 6 of them
Is this Watersheding?
From now on I am going to describe the processes and concepts I learned about watersheding. First, the image above is 2D (of course!) but watersheding can be understood as filling water on a3D map, filling the basins. So to get something like a 3D map, there is the concept of Distance Transform which I haven't tried in OpenCV yet, but I understand as the value of every pixel to the border or the elements they are contained.
So I got a image like this:
And here I can apply watershed to get
You can see that watershed oversegmentates (in red) but by checking the watersheds heigth, I can finally come with a good separation which is the five elements.
As you can see, I didn't need markers. In OpenCV watershed so far I get two areas mistaken as only one area. But in the concept I learned it is actually the opposite: I get one area mistaken as many areas.
So to me watershed is just pouring water on basins and get everything oversegmentated, and by pouring more and more water these basins erase the low watersheds and join, solving the problem of oversegmentation.
Is this conceptually totally different from OpenCV? Can I implement my theoretical concepts?
Any comment, will be greatly appreciated.
Thanks a lot
Your approach works, but the idea behind the OpenCV watershed with markers is that you can initiate places where you start pooring the water in the basins. A python explanation is found here but the concept is the same in C++. This SO topic also explains it pretty well.
Thank you for your comment. I have read both sources and in fact I even commented in the second (it was deleted, quite unfairly if you ask me) and implemented the first one in C++ (it was in Python) . My question is how can I implement the approach I explained above with OpenCV.
(Another thing is that I find the whole "markers" thing strange. I understand that it is perhaps to avoid oversegmentation, but why cant I just start pouring water everywhere and just let the high watersheds, appear themselves. Finding the markers defeat the purpose of watershed in my opinion. But anyway disregard this comment if you wish and back to how can I implement the above ideas in OpenCV
I am not sure I can understand what you wrote. Could you explain it?