[Neuroimaging] 2 questions about Image processing on nifti images

Matthew Brett matthew.brett at gmail.com
Sat Feb 29 08:09:50 EST 2020


Hi,


On Sat, Feb 29, 2020 at 1:02 PM PLANTIN Baptiste
<baptiste.plantin at altran.com> wrote:
>
> Hello team,
>
>
>
> Looking recently about MRI, I’m starting to work using your tool and I have two questions, one relative to a method and one about dataset nii.gz :
>
> -        I’m actually use the Sobel filter on a .nii slices. If the process is successfully done, I don’t know how to create a new nifty image as a Sobel version of the original one. I tried this method:
>
> ·        Load the original nifty image as “img”
>
> ·        Load again the original image as “Sobel”
>
> ·        Use the Sobel filtering on each slices
>
> ·        For each slices (for loop), replace the slice in “Sobel” to the new filtered slice
>
> ·        Save the new Sobel image in the file as “imSobelNumX”

Could you post the code that you are using?

The general idea is:

img = nib.load('my_image.nii')
data = img.get_fdata()
for z_no in range(data.shape[-1]):
    data[..., z_no] = some_filter(data[..., z_no])
new_img = nib.Nifti1Image(data, None, img.header)
nib.save(new_img, 'filtered_image.nii')

Cheers,

Matthew


More information about the Neuroimaging mailing list