speed improvement

vectorization of the convertImage function for speed improvement