필터 지우기
필터 지우기

Get singular sagittal slice from nifti file saved as axial slices

조회 수: 4 (최근 30일)
Malik Ali
Malik Ali 2024년 7월 26일
답변: Walter Roberson 2024년 7월 26일
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 2024년 7월 26일
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