# Help with find_boundaries or watershed

Sigmund siggin at gmail.com
Fri Nov 23 11:13:28 EST 2012

```Moin moin,

I'm using the find_boundaries function for separating labeled regions
(separated by the watershed). Afterward I set the as True returned pixels
to 0.  This works quit well but since my objects (labeled regions) can be
small (couple pixels) and seldom stick together I would like to limit the
find_boundaries to connected regions.
Is there a easy way to only find the boundaries not connected to 0. Or tell
the watershed function to leave a space between separate objects?

Example:
import numpy as np
from scipy import ndimage as nd
from skimage.segmentation.boundaries import find_boundaries
a = np.zeros((15,15))
a[4:9,4:9]=1
a[6:10,7:12]=2
a[1:3,1:3]=3
print "a"
print a.astype(int)
a[find_boundaries(a)]=0
print a.astype(int)

Output:

[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]
[0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]
[0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]
[0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]
[0 0 0 0 0 0 0 2 2 2 2 2 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
After find_boundaries:
[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 3 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 0 1 1 0 0 0 0 0 0 0 0]
[0 0 0 0 0 1 1 0 2 2 2 2 0 0 0]
[0 0 0 0 0 1 1 0 2 2 2 2 0 0 0]
[0 0 0 0 0 0 0 0 2 2 2 2 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]

As you can see, the region 3 is almost gone.

Thanks
Siggi

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20121123/7b3c6760/attachment.html>
```