This question has been moved from stack overflow to here.
My goal is image segmentation but I think my question is a math one:
In computer vision level sets are regularly used to represent moving interfaces. Often the level set function is defined by a signed distance function (SDF). Sometimes the goal in image segmentation is to delineate an object of genus 0, but levels sets change topology quite easily. My question; is there a way to determine if the topology of a level set function has changed?
Here is a sample problem:
This is the image I'm trying to segment:

This is my current result (plotting the zero isocontours of the level set function):

Here is a link to the actual level set function:
My goal is that the zero level set would consist of just one contour, encircling the galaxy. I want to create a detector function which tells me when the topology changes.