In modern microscopy the field of view is often increased by obtaining an image mosaic, where multiple sub-images are taken side by side and combined post-acquisition. Mosaic imaging often leads to long imaging times that can increase the probability of sample deformation during the acquisition due to, e.g., changes in the environment, damage caused by the radiation used to probe the sample, or biologically induced deterioration. Here we propose a technique, based on local phase correlation, to detect the deformations and construct an artifact-free image mosaic from deformed sub-images. The implementation of the method supports distributed computing and can be used to generate teravoxel-size mosaics. We demonstrate its capabilities by assembling a 5.6 teravoxel tomographic image mosaic of microvasculature in whole mouse brain. The method is compared to existing rigid stitching implementations designed for very large datasets, and observed to create artifact-free image mosaics in comparable runtime with the same hardware resources.