In the above code, the -x option reorients and crops the image. 
The second step in preprocessing was to correct for differences in positioning. The acpcdetect program (64-bit v2.0 which is part of the NITRC Automatic Registration Toolbox) was used to align the images along the anterior and posterior commissure based on a midsagittal image.  Each image was oriented by midpoint between the anterior and posterior commissures (indicated by the -M option in the code).  This program was downloaded from https://www.nitrc.org/frs/download.php/6494/acpcdetect.tar.gz.