Remove background from leaf scans and improve error handling