Hi Siggi,<div><br></div><div>How about replacing</div><div><br></div><div>>>> a[find_boundaries(a)]=0</div><div><br></div><div>with</div><div><br></div><div>>>> s = nd.generate_binary_structure(2, 1)</div>

<div>>>> a[find_boundaries(a) * (nd.grey_erosion(a, footprint=s) != 0)] = 0</div>
<div><br></div><div>?</div><div><br></div><div>That will leave you with big objects that are separated with respect to connectivity=1, and objects that aren't touching will not be "reduced".</div><div><br></div>

<div>The output for your example is:</div><div><br></div><div><div>>>> print a.astype(int)</div><div>[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]</div>

<div> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]</div><div> [0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]</div><div> [0 0 0 0 1 1 1 0 0 2 2 2 0 0 0]</div><div> [0 0 0 0 1 1 1 0 2 2 2 2 0 0 0]</div><div>
 [0 0 0 0 1 1 1 0 2 2 2 2 0 0 0]</div>
<div> [0 0 0 0 0 0 0 2 2 2 2 2 0 0 0]</div><div> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]</div><div>
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]</div>
</div><div><br></div>
<div>Juan.</div><div><div><br><div class="gmail_quote">On Sat, Nov 24, 2012 at 3:13 AM, Sigmund <span dir="ltr"><<a href="mailto:siggin@gmail.com" target="_blank">siggin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Moin moin,<br><br>
<p style="margin-bottom:0cm" lang="en-US">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.<br>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?</p>
<br>Example:<br><font size="1"><span style="font-family:courier new,monospace">import numpy as np<br>from scipy import ndimage as nd<br>from skimage.segmentation.boundaries import find_boundaries<br>a = np.zeros((15,15))<br>


a[4:9,4:9]=1<br>a[6:10,7:12]=2<br>a[1:3,1:3]=3<br>print "a"<br>print a.astype(int)<br>a[find_boundaries(a)]=0<br>print a.astype(int)</span></font><br><br>Output:<br><br>[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]<br>


 [0 3 3 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]<br> [0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]<br> [0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]<br> [0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]<br> [0 0 0 0 1 1 1 2 2 2 2 2 0 0 0]<br>


 [0 0 0 0 0 0 0 2 2 2 2 2 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]<br>After find_boundaries:<br>


[[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 3 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 1 1 1 1 0 0 0 0 0 0]<br> [0 0 0 0 0 1 1 0 0 0 0 0 0 0 0]<br>


 [0 0 0 0 0 1 1 0 2 2 2 2 0 0 0]<br> [0 0 0 0 0 1 1 0 2 2 2 2 0 0 0]<br> [0 0 0 0 0 0 0 0 2 2 2 2 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br> [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]<br>


 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]<br><br>As you can see, the region 3 is almost gone.<br><br>Thanks<br>Siggi<span><font color="#888888"><br><br>

<p></p>

-- <br>
 <br>
 <br>
</font></span></blockquote></div><br></div></div>