Improving the domain generalization and robustness of neural networks for medical imaging