Applies the watershed filter to an image, i.e., separating it in nearly homogeneous regions.


In [1]:
medpy_watershed.py resources/b0.nii.gz output/watershed.nii.gz

Looking at our result we get

</tr>

Original image

Region image </tr> </table> That is not quite what we expected. If your resulting imageshows this gradient-like transition of gray values from one to the other site, it means that too many regions where created. In fact, this can result in that many regions, that the numeric type overflows.

To fix this, let's first take a look at the script's parameters.


In [2]:
medpy_watershed.py -h


usage: medpy_watershed.py [-h] [--mindist MINDIST] [--mask MASK] [-v] [-d]
                          [-f]
                          input output

Applies the watershed segmentation an image using the supplied parameters.
Note that this version does not take the voxel-spacing into account. If you
require this function, please take a look at the medpy_itk_watershed.py
script. Copyright (C) 2013 Oskar Maier This program comes with ABSOLUTELY NO
WARRANTY; This is free software, and you are welcome to redistribute it under
certain conditions; see the LICENSE file or <http://www.gnu.org/licenses/> for
details.

positional arguments:
  input              Source volume (usually a gradient image).
  output             Target volume.

optional arguments:
  -h, --help         show this help message and exit
  --mindist MINDIST  The minimum distance between local minima in voxel units.
  --mask MASK        Optional binary mask image denoting the area over which
                     to compute the watershed.
  -v                 Display more information.
  -d                 Display debug information.
  -f                 Silently override existing output images.

Note the MINDIST value. With this, the minimal distance between to local minima can be set and thus the minimal size of the regions roughly controlled. let's try it.


In [3]:
medpy_watershed.py resources/b0.nii.gz output/watershed.nii.gz --mindist 10 -f
Original image Region image Region image (colored)

Better. In the colored version, the brain becomes visible.


In [ ]: