From jy_wang at ucsb.edu Fri Nov 4 19:31:53 2022
From: jy_wang at ucsb.edu (Jingyi Wang)
Date: Fri, 4 Nov 2022 16:31:53 -0700
Subject: [Neuroimaging] Find masked data voxel coordinates in the original
Nifiti structure
Message-ID:
Dear all,
I computed a vector that each element in the vector corresponding to each
voxel in my mask. I want to find out a way to put those values back to
Nifiti data structure in the original mask file space.
The total number of elements in the vector is exactly the same as the
number of voxels in my mask. I used "nib.load" from the nibabel package to
get the data for the whole brain time series. I load the mask file using
"image.load_img" from the nilearn package, then mask the whole brain time
series using "apply_mask" from the nilearn package. After masking, I got a
2D matrix with each column in the matrix corresponding to a voxel in the
mask region. Then I did some computations to this 2D matrix that reduced
this matrix into a vector, which the index of each element correlates with
the original 2D matrix column index.
I am trying to find whether there is a command that allows me to find the
coordinates in Nifiti structure data for each column (that corresponds to
the voxel) in the 2D matrix (that I got from "apply_mask").
I also tried the command "new_img_like", but failed as I don't know how to
find the element coordinates to the original 3D numpy array.
Thanks in advance!
Jingyi
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From sulantha.s at gmail.com Fri Nov 4 20:02:03 2022
From: sulantha.s at gmail.com (Sulantha Sanjeewa)
Date: Fri, 4 Nov 2022 17:02:03 -0700
Subject: [Neuroimaging] Find masked data voxel coordinates in the
original Nifiti structure
In-Reply-To:
References:
Message-ID:
Hi,
You may be able to simply do,
zeros = numpy.zeros_like(mask_file_data)
zeros[numpy.where(mask_file_data > 0.5)] = vector
and then use the zeros to create a new Nifti1Image as mentioned in
https://bic-berkeley.github.io/psych-214-fall-2016/saving_images.html
Best regards,
Sulantha
On Fri, Nov 4, 2022 at 4:32 PM Jingyi Wang wrote:
> Dear all,
>
> I computed a vector that each element in the vector corresponding to each
> voxel in my mask. I want to find out a way to put those values back to
> Nifiti data structure in the original mask file space.
>
> The total number of elements in the vector is exactly the same as the
> number of voxels in my mask. I used "nib.load" from the nibabel package to
> get the data for the whole brain time series. I load the mask file using
> "image.load_img" from the nilearn package, then mask the whole brain time
> series using "apply_mask" from the nilearn package. After masking, I got a
> 2D matrix with each column in the matrix corresponding to a voxel in the
> mask region. Then I did some computations to this 2D matrix that reduced
> this matrix into a vector, which the index of each element correlates with
> the original 2D matrix column index.
>
> I am trying to find whether there is a command that allows me to find the
> coordinates in Nifiti structure data for each column (that corresponds to
> the voxel) in the 2D matrix (that I got from "apply_mask").
>
> I also tried the command "new_img_like", but failed as I don't know how to
> find the element coordinates to the original 3D numpy array.
>
> Thanks in advance!
>
> Jingyi
>
>
> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: