If you have 1 pixel wide contour lines, then you can calculate the number of neighbors for each point * . If each point of a given circuit has 2 neighborhoods, then the circuit is closed. If there are 2 points with only one neighbor, then the circuit is open.
If your contours are thicker, you can apply the skeletonization algorithm to make them exactly 1 pixel. An interesting case is when there are side branches on the contour, but in this case there should be branch points with 3 neighbors, so these situations can be easily handled.
* Counting neighbors is simple: use the original image! Select one contour point randomly, check the adjacent 8 pixels and count those parts that are part of the contour. Then repeat the neighbor check for them, etc., until all the pixels in the path are checked.
source share