Added type checks when casting to Image<T> from Buffer

Also caught a bug in one of the tests
Merge branch 'master' of github.com:halide/Halide