Detection, Rectification and Segmentation of Coplanar Repeated Patterns