Optimization of second-harmonic generation microscopy