Refactored and improved active snake algorithm