Ask Your Question
1

watershed algorithm to image with grey background

asked 2017-08-19 06:46:21 -0600

chetanreddy gravatar image

updated 2019-12-09 08:19:47 -0600

Akhil Patel gravatar image

I have an image with grey backgound to which i want to apply watershed algorithm.

But as I am trying to threshold the grey scaled image, the background is also is being converted to white(binary+otsu thresholding).
I thought of applying the grabcut algorithm to my image first then apply watershed.

I have no idea how to implement this.
Any help in this regard would be appreciated?

edit retag flag offensive close merge delete

Comments

please post the code you tried and the sample image

sturkmen gravatar imagesturkmen ( 2017-08-19 07:00:06 -0600 )edit

@sturkmen I have added a sample image

chetanreddy gravatar imagechetanreddy ( 2017-08-19 07:50:41 -0600 )edit

@chetanreddy did you delete your question after accepting answer?

sturkmen gravatar imagesturkmen ( 2017-08-21 08:12:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-08-20 18:58:10 -0600

updated 2017-08-20 19:10:03 -0600

this example program demonstrates using watershed

but you need some preprocessing like below ( add this piece of code to imageSegmentation.cpp line 26)

Mat img_gray;
cvtColor(src, img_gray, cv::COLOR_BGR2HSV);

Mat hsv[3];
split(img_gray, hsv);

img_gray = hsv[2] + hsv[1];
imshow("img_gray", img_gray);
src.setTo(Scalar(0, 0, 0), ~img_gray);
    // ( this code is suitable for bright objects on gray background )

this step will give you the image below

image description

and you will finally get the image below.

image description

edit flag offensive delete link more

Comments

How come your objects are so overly segmented? Using the linked tutorial and following this approach this should not happen :)

StevenPuttemans gravatar imageStevenPuttemans ( 2017-08-21 08:56:06 -0600 )edit
1

i am not experienced with watershed. indeed as i do most of the time. i tried to change something with existing code and share the result. i have no deep understanding about what goes here :)

sturkmen gravatar imagesturkmen ( 2017-08-21 09:23:58 -0600 )edit

I will have a look at it tomorrow ๐Ÿ˜€

StevenPuttemans gravatar imageStevenPuttemans ( 2017-08-21 11:47:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-19 06:46:21 -0600

Seen: 357 times

Last updated: Aug 21 '17