MATLAB Answers

overlay nifti mask on nifti volume

48 views (last 30 days)
SJDS
SJDS on 7 May 2021
Commented: Asvin Kumar on 11 May 2021
i have a 3d MRI in nifti format and a 3d binary mask in nifti. how to overlay the mask on the volume and eliminate the undesired regions?
NOTE: I want to apply glcm on the result.
Mask:

Answers (1)

Asvin Kumar
Asvin Kumar on 10 May 2021
You can use the niftread function to import your 3D data.
Once imported, it behaves just like any 3D matrix. You can then apply your 3D binary mask on that data.
Once processed, you can save your output using the niftiwrite function.
Here's an example of processing NIfTI data that applies a 3D median filter on the imported volume: Write Median-Filtered Volume to NIfTI File This example should give you an idea of what you can do.
  2 Comments
Asvin Kumar
Asvin Kumar on 11 May 2021
I'm not a 100% sure about how MRI data is represented. Since you mention that you want to apply GLCM on this masked MRI, I assume, that the lowest value for MRI voxels is 0 and that stands for 'low'. You can adjust this as required.
If you had a 3D matrix, here's how you could apply a binary mask.
vol = randi(10,[4 4 6]) % similar to original MRI data
vol =
vol(:,:,1) = 3 5 3 3 10 5 6 1 4 3 6 9 1 5 1 2 vol(:,:,2) = 5 1 2 6 9 5 1 3 4 10 2 10 8 8 3 10 vol(:,:,3) = 1 9 2 9 1 5 2 9 5 8 7 1 9 8 10 7 vol(:,:,4) = 6 2 9 2 1 9 1 5 4 7 7 6 1 8 9 7 vol(:,:,5) = 5 3 3 2 3 5 5 2 9 5 1 8 1 5 2 8 vol(:,:,6) = 3 10 4 7 7 7 1 4 7 5 8 7 3 6 9 5
mask = vol>7; % creating my own binary mask
maskedVol = vol;
maskedVol(~mask)=0 % setting to 0 if values of voxel is not >7
maskedVol =
maskedVol(:,:,1) = 0 0 0 0 10 0 0 0 0 0 0 9 0 0 0 0 maskedVol(:,:,2) = 0 0 0 0 9 0 0 0 0 10 0 10 8 8 0 10 maskedVol(:,:,3) = 0 9 0 9 0 0 0 9 0 8 0 0 9 8 10 0 maskedVol(:,:,4) = 0 0 9 0 0 9 0 0 0 0 0 0 0 8 9 0 maskedVol(:,:,5) = 0 0 0 0 0 0 0 0 9 0 0 8 0 0 0 8 maskedVol(:,:,6) = 0 10 0 0 0 0 0 0 0 0 8 0 0 0 9 0

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!