[Core] Border detection algorithm