help > RE: Saving Flipped Brain Images
Dec 10, 2023  07:12 PM | Chris Rorden
RE: Saving Flipped Brain Images

Hello,


  MRIcron is a visualization tool, not an image manipulation tool. The View/FlipLR is designed to change between neurological and radiological orientation.


 


You could try MRIcroGL, which has the Import/Tools/Rotation menu item.


 


Alternately, you could write a Python script. Here is what ChatGPT suggests:


--------------


import nibabel as nib
import numpy as np


def flip_first_dimension(input_path, output_path):
    # Load the NIfTI file
    img = nib.load(input_path)
    data = img.get_fdata()


    # Flip the order of voxels in the first dimension
    flipped_data = np.flip(data, axis=0)


    # Create a new NIfTI image with the flipped data
    flipped_img = nib.Nifti1Image(flipped_data, img.affine, img.header)


    # Save the flipped NIfTI file
    nib.save(flipped_img, output_path)
    print(f"Flipped NIfTI file saved to {output_path}")


if __name__ == "__main__":
    # Replace 'input_file.nii.gz' and 'output_file.nii.gz' with your file paths
    input_file_path = 'input_file.nii.gz'
    output_file_path = 'output_file.nii.gz'


    flip_first_dimension(input_file_path, output_file_path)

Threaded View

TitleAuthorDate
Emily Narinsky Dec 8, 2023
RE: Saving Flipped Brain Images
Chris Rorden Dec 10, 2023