Moved template creation to its own function

Templates are now created in a helper function.
There is a function that only gives the contrast image that can be used
if wanted.
The edge detection function is moved out as a helper function to the one
called by main, to ease using several channels combined.