Implemented template-detection

Implemented templatedetection, and created and modified utility files
that is likely to be used by a large portion of the image processing.