Fix bug in cube_to_image function