[scikit-image] fill closed contour

Randy Heiland randy.heiland at gmail.com
Sun Jan 7 20:21:01 EST 2018


Sure - thanks.

from skimage.morphology import disk
from skimage.feature import canny
from scipy import ndimage as ndi
import matplotlib.pyplot as plt

image = disk(100)
for ix in range(200):
  for iy in range(200):
    xdel=ix-100
    ydel=iy-100
    if (xdel*xdel/50 + ydel*ydel/10) < 110:
      image[iy,ix]=0
    elif (xdel*xdel/10 + ydel*ydel/50) < 110:
      image[iy,ix]=0

edges = canny(image*255.)  # canny expect grayscale, i.e. 0-255 ??!

fill = ndi.binary_fill_holes(edges)   # I don't understand the params; can
I seed a region to fill?

fig, axes = plt.subplots(ncols=3, figsize=(9, 3))
ax = axes.ravel()

ax[0].imshow(image, cmap=plt.cm.gray, interpolation='nearest')
#ax[0].imshow(invert_img, cmap=plt.cm.gray)
#ax[0].set_title('Inverted image')
ax[0].set_title('Original image')

ax[1].imshow(edges*1, cmap=plt.cm.gray, interpolation='nearest')
ax[1].set_title('Canny edges')

ax[2].imshow(fill, cmap=plt.cm.spectral, interpolation='nearest')
ax[2].set_title('Fill')

plt.show()



On Sun, Jan 7, 2018 at 6:57 PM, Juan Nunez-Iglesias <jni.soma at gmail.com>
wrote:

> Hi Randy, I was going to suggest binary fill holes. Do you mind posting
> your image and the code you’ve tried so we can troubleshoot?
>
> Thanks,
>
> Juan.
>
> On 8 Jan 2018, 9:48 AM +1100, Randy Heiland <randy.heiland at gmail.com>,
> wrote:
>
> If I have a binary image with, say, just a contour boundary (simple
> example: a white background with a black circle, i.e. an "o"), how can I
> fill the inside of the contour? I've played with both the watershed
> segmentation and the scipy.ndimage.binary_fill_holes, without success.
>
> thanks, Randy
> _______________________________________________
> scikit-image mailing list
> scikit-image at python.org
> https://mail.python.org/mailman/listinfo/scikit-image
>
>
> _______________________________________________
> scikit-image mailing list
> scikit-image at python.org
> https://mail.python.org/mailman/listinfo/scikit-image
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20180107/2a370100/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ring_fill.png
Type: image/png
Size: 20093 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20180107/2a370100/attachment-0001.png>


More information about the scikit-image mailing list