title: How to modify orientation of mgh/dicom/nifti file using nibabel
body: <p>I have a hard time, figuring out a proper affine transformation for 3 different views i.e. coronal, axial and saggital, each having separate issues like below:</p>
  
  <p>1: Axial color map get overlapped with the saggital original view.</p>
  
  <p><a href="https://i.stack.imgur.com/43cAi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/43cAi.png" alt="enter image description here"></a></p>
  
  <p>2: Similarly Sagittal color map gets overlapped with the axial original image.</p>
  
  <p><a href="https://i.stack.imgur.com/7pIJh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7pIJh.png" alt="enter image description here"></a></p>
  
  <p>3: And everyone has some kind of orientation issues like best visible here when the color map and original image for coronal come correct but with wrong orientation. </p>
  
  <p><a href="https://i.stack.imgur.com/D5AWG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D5AWG.png" alt="enter image description here"></a></p>
  
  <p>I am saving the original file that I am sending to the server for some kind of prediction, which generates a color map and returns that file for visualization, later I am displaying everything together.</p>
  
  <p>In server after prediction, here is the code to save the file.</p>
  
  <pre><code> nifti_img = nib.MGHImage(idx, affine, header=header)
  </code></pre>
  
  <p>Whereas <strong>affine</strong> and <strong>header</strong> are the original affine and header extracted from the file I sent.</p>
  
  <p>I need to process <strong>"idx"</strong> value that holds the raw data in Numpy array format, but not sure what exactly to be done. Need help here.</p>
  
  <p>Was trying hard to solve the issue using <strong>nibabel</strong> python library, but due to very limited knowledge of mine about how these files work and about affine transformation, I am having a hard time figuring out what should I do to make them correct.</p>
  
  <p>I am using AMI js with <strong>threejs</strong> support in the frontend and nibabel with python in the back end. Solution on the frontend or back end anywhere is acceptable.</p>
  
  <p>Please help. Thanks in advance.</p>