How can you thicken a white line in a binary mask?

MaxFilter propagates the neighborhood maximum, growing white foreground outward.

Pixel experiment and interpretation

One white seed is enough to measure the growth footprint. Nearby objects can merge when the expansion closes the gap.

from PIL import Image, ImageFilter

im=Image.new('L',(5,5))
im.putpixel((2,2),255)
im.filter(ImageFilter.MaxFilter(3)).getbbox()

Result (1, 1, 4, 4)

中文

如何加粗二值掩膜里的白色细线?

MaxFilter 把邻域最大值传播到中心,白色前景因而向外生长。

像素实验与适用边界

只标一个白点就能测出增长范围。相邻对象间距很小时,扩张会让本应独立的掩膜连起来。

from PIL import Image, ImageFilter

im=Image.new('L',(5,5))
im.putpixel((2,2),255)
im.filter(ImageFilter.MaxFilter(3)).getbbox()

结果 (1, 1, 4, 4)

References / 参考来源

Keep reading / 继续阅读