Get singular sagittal slice from nifti file saved as axial slices

7 次查看(过去 30 天)
Hello, with the following code i'm able to retrieve a single axial slice from this nifti file of a lung CT scan. I would like to know how to be able to save a slice from another view, such as sagittal or coronal in a separate image format such at png or jpg for image processing.
L1 = load_nii('lung_029.nii');
NumSlices = size(L1.img,3)
S = L1.img(:,:,125);
figure
imshow(S)
I'm using the image processing toolbox and tools for nifti and analyze image add ons.

回答(1 个)

Walter Roberson
Walter Roberson about 17 hours 前
Example
L1 = load_nii('lung_029.nii');
S = size(L1.img);
r1 = randi(S(1));
r2 = randi(S(2));
r3 = randi(S(3));
view1 = reshape(L1.img(r1,:,:), S(2), S(3));
view2 = reshape(L1.img(:,r2,:), S(1), S(3));
view3 = reshape(L1.img(:,:,r3), S(1), S(2));
imwrite(view1, 'view1.png');
imwrite(view2, 'view2.png');
imwrite(view3, 'view3.png');
I should note, though, that most of the time you do not need to save the extracted data into an image file in order to process it; most of the time you can just use the arrays (view1, view2, view3) directly.

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by