Modified function to accept path name or scan images as a parameter