Stabilizing Ultrafast Electron Microscopy Imaging for Custom Optics