Let’s say we have a dark donut on a white background. What is a good way, looking only at any pixel’s value (0 = not white, 1 = white) and any neighbouring pixel values, to determine which one of the two white regions found on the image is inside the donut?

(source: 123rf.com)
In computer graphics, this problem has been extensively studied in the context of geometry processing. The goal is to know whether a point is outside or outside a polygon (possibly with holes), and has been used for color filling for example.
The most common solution is to throw a line in a random direction from your current point (for simplicity, you can take an horizontal scan line), and count the number of intersections with the boundary. If this number is even, you are outside, and if it is odd, your are inside.
In the context of image processing, finding the boundary can be done with edge finding techniques (for instance, the Sobel operator). You can now just walk on a single row from your given point to the right (for instance) and count how many edges you found.