remove a contour from image using skimage
<p>I want to remove some contour from an image but I don't know how to achieve it using <code>skimage</code>? I do something like this in <code>OpenCV</code> using <code>drawContour</code> but I can't find the equivalent in <code>skimage</code>.</p>

<p>Assume I have a simple image like:</p>

<pre><code>0 0 0 0 0 0 0 0

0 0 1 1 1 1 0 0

0 0 1 0 0 1 0 0

0 0 1 1 1 1 0 0

0 0 0 0 0 0 0 0
</code></pre>

<p>that has only one connected component. </p>

<p>I need to remove it by masking it. </p>

<p>The final result will be a 8 * 5 zero matrix!</p>

<pre><code>a = '''0 0 0 0 0 0 0 0                                             
0 0 1 1 1 1 0 0
0 0 1 0 0 1 0 0
0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0'''
np.array([int(i) for i in a.split()], dtype=bool).reshape(5, 8)
cc = measure.regionprops(measure.label(a))[0]
# here is what I do for removing cc
</code></pre>

<p>What should I do to remove <code>cc</code> connected component using <code>skimage</code>?</p>

<p>skimage have equivalent function: </p>

<pre><code>contours=skimage.measure.find_contours(array, level, fully_connected='low', positive_orientation='low')
</code></pre>

<p>find_countours return value is an array of numpy arrays each of which contain specific contour. Then you can just select specific contour by index from contours and iterate through your image by addresses of pixels which belong to specific contour, setting them to 0. </p>

<p>In your case you should have only one contour, so:</p>

<pre><code>c=contours[0]
n=contours[0].shape[0]

for i in range(0,n):
 for j in range(0,n):
   image[c[i]][c[j]]=0
</code></pre>

python image-processing skimage