I used to use auto_reorient.m script to reorient MR images. However, this script doesn’t work with current SPM12 anymore since spm_affreg.m is gone.
Therefore, I thought of another way to reorient images automatically.
The simple way is to coregister images to MNI images. However, if origin is too far from center of the image, it is likely to fail. So before coregistration, I set the origin of the image to the center, then coregister the image to MNI (icbm152.nii under spm12/toolbox/DARTEL).
I tested the script with various images and it works fine.
If you are interested, you can get the script from the link below.
Download acpc_coreg.m (Right click -> Save as)
Save the script under directory to which Matlab path is set, then type
from Matlab command window.
You need SPM12 for this script.