refactor detectImage