I have a black-and-white (binary) image. It contains a set of black blobs, surrounded by white. I am trying to write a C# program that will find a single path to cross through all of the shaded area, while leaving out as much of the white area as possible. This is very similar to finding a toolhead path for a 3D printer for any given layer; it needs to fill the solid parts, while only crossing in to empty space when it needs to get to another separate blob.
For example, here's a test image that I have created, that includes most of the challenges that I am facing (with only two blobs for simplicity):
I would want to find a path that would cross through all the black areas, while only crossing the white once to jump between the two shapes (where they are closest). I would also want the path to be as short as possible.
My program is written in C#, and I am already using AForge for image manipulation up to this point, so I already have that accessible.
So far, the closest that I got was with a flood-fill-like algorithm. It would start at a corner, and find the closest pixel(horizontally first, then vertically), to continue the path. But the paths didn't always go everywhere, and crossing over usually created a long and largely extraneous path. I also tried tracing the edges and going inward, but it still didn't work very well when a blob had a non-straight path. Searching didn't come up with much either; I tried searching for things relating to 3D printing algorithms, flood-fills, etc, but not much came up.
So, how should I tackle this?