view nii gz files in 3D

33 Ansichten (letzte 30 Tage)
Daniele Evangelista
Daniele Evangelista am 22 Okt. 2023
Beantwortet: Garmit Pant am 3 Nov. 2023
Hello everyone, after some time I find myself needing to open .nii.gz files.
This is my code but despite various tests I can't understand why it doesn't work.
Eventually I remember that I was able to rotate the 3D image along the 3 Cartesian axes.
I also attach photos of the result I would like to obtain.Can someone help me?Thank you all and have a good evening.
clear all;
clc;
cons = niftiinfo("C:\Users\...path...\Consensus.nii.gz");
v = niftiread(cons);
c = v(:,:,:);
imshow(c);

Antworten (1)

Garmit Pant
Garmit Pant am 3 Nov. 2023
Hello Daniele,
I understand that you are trying to read the .NII.GZ files and then view the 3D image in MATLAB and you are facing an error in the process.
Since you have not specified the error, I have identified some possible points of error in the code.
Since you are trying to import 3D images, the ‘imshow’ function can be throwing an error since the function is used to display 2D images. For inputs with 3 dimensions, the function ‘imshow’ accepts 2D RGB images of shape mxnx3. The shape of the input ‘c’ could be incompatible with the expected argument size. You can create a ‘blockedImage’ object and use the ‘volshow’ function to display the image. Refer to the following example:
There can also be an error in reading the .nii.gz files. You can read the files directly using the ‘niftiread’ function since it accepts files of .nii.gz extension. You can also try to first extract the .nii files from the compressed .nii.gz files by using the ‘gunzip’ function as follows.
files = gunzip("C:\Users\...path...\Consensus.nii.gz");
v = niftiread(files);
For further understanding, you can refer to the following MATLAB Documentation:
  1. https://www.mathworks.com/help/images/ref/niftiread.html#d126e241318 Refer to the input arguments section to check all permissible inputs.
  2. https://www.mathworks.com/help/matlab/ref/gunzip.html - Documentation for gunzip’.
I hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by