Rewriting getImageArray to write the image array to the scope variable.