Is there an algorithm that would perform well in terms of filling holes like those on the sample image? Dilation doesn\'t work well, cause before I eventually manage to conn
After you get the thickened image, you can recover your "thin" shape using skeletonization. I found an implementation of skeletonization here.
If you want avoid too much thickening (as it distorts the image and parts of the shape merge together), use mild erosion and skeletonization alternatively until you get the holes filled.