I have a binary image that represents a number in MATLAB:

I\'d like to fill all the d
Assuming the top-left pixel is always outside the regions to filled:
Work across the top line, copying pixels to the output image
When you come to a white pixel followed by a black pixel in the input image, start setting white pixels in the output image, until you come to black pixel followed by a white pixel.