COMP: Rearranged ImageMath function

This fixes the bug introduced as part of adapting to limitations of Visual Studio 2010.

I took the gigantic switch statement in the ImageMath function, and replaced it with template functions specific to each dimension.  It's a lot easier to see what functions are available for each image DImension.