# Imfill Equivalent

**URL:** <https://discourse.julialang.org/t/imfill-equivalent/4772>\
**Category:** Visualization\
**Tags:** images\
**Created:** [July 10, 2017, 8:34pm UTC](https://discourse.julialang.org/t/imfill-equivalent/4772 "2017-07-10T20:34:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rand5](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rand5/32/867_2.png) [@rand5](https://discourse.julialang.org/u/rand5)\
**Post date:** [July 10, 2017, 8:34pm UTC](https://discourse.julialang.org/t/imfill-equivalent/4772/1 "2017-07-10T20:34:04Z")

</div>

I am aware of the erode/dilate and opening/closing functionality in the Images package, but is there an equivalent to Matlab’s imfill to fill image regions and holes?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [July 11, 2017, 11:47am UTC](https://discourse.julialang.org/t/imfill-equivalent/4772/2 "2017-07-11T11:47:47Z")

</div>

You can use `lbl = label_components(img, 1:ndims(img), -1)` to generate a distinct integer label for each region. `lbl != idx` would return a binary image where all pixels with a label different from `idx` were true, so if you choose `idx` to be the label assigned to what you consider to be “background”, that should give you `imfill`.
