The image is preprocessed before its usage, firstly Gaussian blur is used to remove small artifacts that could pollute the result. I could be also done by using image downsizing and upsizing as I presented in the post about breaking captcha. Secondly the image is converted to black and white version to simplify the implementation.
Edges found by using a genetic algorithm (100 generations):
In presented version each children has only one parent, so gene change is provided only by mutation. Each specimen has two genes: X and Y that describes a location on the image. If a specimen has a good set of genes (they point to a location near the edge), then he's healthy and strong so he can breed, but if his genes are weak, then he's weak too and soon he dies. The edge is defined by a fitness function as a point that has neighbor points with different color.
Strong species breed so after couple of generations theirs children will cover the whole edge. The final result is a set of genes (each is a point on the image) in the last generation.
The implementation was done in Java, the source code can be cloned from GitHub (GeneticEdgeDetection directory). To use this project, JRE needs to be installed and assumed that you have JRE installed and java.exe should be added to the PATH enviroment.
Usage: open project directory in command line, go to the dist directory and type:
java -cp EdgeDetector.jar edgedector.Main ../sample.jpg
You can verify and observe the program with different input images, just change the last argument.
The results take a lot of time to be computed, but they are really good. After some point, adding new generations don't improve the result, maybe this could be solved by improving a part responsible for gene mutation. It's visible on below diagram:
The diagram was created by using a gnuplot script that is stored in tools subdirectory. Its body contains info, how to use it.
Better results could be obtained with more sophisticated fitness function and/or by switching to a greyscale image.