Ask Your Question
1

Watershed. Basic question

asked 2015-02-06 03:22:22 -0600

KansaiRobot gravatar image

Hello and thanks always for your help.

I have a question regarding the concept and application of watershed in OpenCV

So far I have tried several examples both the example in the opencv library as well as other. It seems the concept is:

1) First , mark several markers 2) Then apply the watershed function

However for it to work well I have to mark these markers or find them somehow. Now, let's say I have the following image description

(disregard, the duplicate, both images are the same)

In it you can see that I have the areas which are not background, and I want to use watershed to separate those areas. (the original image have some dark edges if that helps). If I erode these areas, they are still be connected right?

So what if I apply watershed then. I tried and I obtain the areas a one piece and not as separated objects.

My question is that if I have to find the markers other way, what good is the watershed then? I want to use watershed function precisely to separate these areas.

What I am doing wrong? Any advice on how to separate these areas??

Thanks a thousand

edit retag flag offensive close merge delete

Comments

I think that is because you have the same value on the markers (255). In wathershed, the markers shall have different values. So the markers' mask shall be something like this: 0,0,0,0,1,1,1,1,0,0,0,0,0,2,2,2,2,0,0,0,0,0,3,3,3,3,3,3,3.... If you understand what I mean

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-02-06 04:18:14 -0600 )edit

Yes, but that is precisely why I am using watershed. to differentiate those areas.

KansaiRobot gravatar imageKansaiRobot ( 2015-02-08 18:26:38 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2015-02-06 10:31:22 -0600

Guanta gravatar image

I don't know if I get you right. So, you want to know why you should use Watersheds since you need to place some markers. So watershed is a segmentation algorithm (like graphcut) which needs some supervision, e.g. what is foreground and what is background, then it trys to segment both parts. And yes, you need to find those markers in a different way. Thus, it depends on your application if you need it or not.

edit flag offensive delete link more

Comments

Thats right, but if he wants to segment foreground vs background, the markers from the foreground must have a different pixel value then the ones from the background.

Pedro Batista gravatar imagePedro Batista ( 2015-02-06 10:37:19 -0600 )edit

is there any segmentation algorithm which can segment the foreground from background automatically without any suervision?

jamesnzt gravatar imagejamesnzt ( 2015-02-06 11:35:35 -0600 )edit

That depends on your problem. If your setup is not too dynamic and your objects distinct enough from the background, you can try to apply some background subtraction algorithm and then apply different markers for each element (backgroud included). If your background is always very bright and your objects dark (or the other way around) a simple threshold operation will suffice.

It depends a lot on your setup, so we will be able t help you further if you describe your problem.

Pedro Batista gravatar imagePedro Batista ( 2015-02-06 12:05:03 -0600 )edit

My problem is to detect the leaf which is fully present in the image as stated in question

jamesnzt gravatar imagejamesnzt ( 2015-02-06 23:50:27 -0600 )edit

Pedro, I have no problem so far segmenting the background from the foreground. My problem starts when the foreground is segmented as one region when in fact it is two. If I have to separate this manually to find the markers, then what is the goodness of watershed??

KansaiRobot gravatar imageKansaiRobot ( 2015-02-09 00:10:18 -0600 )edit
0

answered 2015-02-08 18:15:50 -0600

KansaiRobot gravatar image

updated 2015-02-08 18:23:24 -0600

thank you for your replies and sorry if I wasn't clear. Let me explain again.

Let's say I have two areas that I can clearly see they are different. These areas touch each other.

Now, the method for watershed is, first find the background. Well that is relatively easy. So I have the background and I mark it with some number.

Now the next step is find the foreground and mark each interested area with a different number. So in this case if I have two areas I have to find the sure foreground and mark it with two different values. and then apply watershed.

But that is precisely why I am using watershed!! to differentiate these two foreground areas! I mean what is the point of using watershed if I have to use another method to find and differentiate those foreground areas.

Using thresholding and morphology the best I can do is find which part of the image is sure foreground but I can not differentiate which part is of one region and ore of other region. How can I solve this dilemma???

thanks a thousand

edit flag offensive delete link more
0

answered 2015-02-09 02:28:31 -0600

thdrksdfthmn gravatar image

If you know that the foreground has 2 separate areas/regions, then why aren't you just segment it once more? eg: you have subtracted the background, so you have the mask for the foreground that has 2 pats, like light and dark, then create the foreground image:

image.clone(foreground, foregroundMask);

Then segment it with threshold, so you are goinf to have 2 regions.

If your problem is a more complex, then you should think of how to define the 2 markers for the foreground, so watershed will segment it correctly.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-02-06 03:22:22 -0600

Seen: 444 times

Last updated: Feb 09 '15