How to use spatial filtering and matrix operation to find the intersection (red points) and end points (blue points) Maze example