Segmentation algorithm of complex ore images based on templates transformation and reconstruction