Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image segmentation of connected objects with watershed

I'm trying to separate connected objects. It seems that Python and the watershed algorithm (scipy implementation) are well-suited to handle this.

Here is my image and automatically generated watershed seed points (local maxima of the thresholded and distance-transformed image):

seeds = myGenSeeds( image_grey )

enter image description here

So far, so good; there is a seed for every object.

Things break down when I run the watershed though:

segmented = ndimage.measurements.watershed_ift( 255 - image_grey, seeds)`

enter image description here

Both the top-middle cluster and the centre cluster are poorly separated. In the top cluster, one object flooded around the other two. In the centre cluster, though it might be too small to see here, the centre seed flooded to only a few pixels.

I have two questions:

  1. Is the watershed algorithm a good choice for separating objects like this?
  2. If so, is there some sort of pre-processing that I've got do do to make the image more suitable for watershed segmentation?
like image 439
ajwood Avatar asked Oct 15 '13 15:10

ajwood


1 Answers

I found this thread because I am having the same problem with watershed_ift. I recommend just using the watershed function in skimage.morphology. It accepts float inputs, so you don't lose resolution on the greyscale image, and it actually floods the entire basin, while the ift approach only seems to flood the isovalues where the markers lie.

EDIT: Be sure to multiply your distance transform by -1 so the peaks become valleys, or else you won't get any watersheds!

like image 78
2cynykyl Avatar answered Sep 28 '22 11:09

2cynykyl