Message Passing Coursework: Reverse edge-detection algorithm