Optimization of light fields in ghost imaging using dictionary learning