필터 지우기
필터 지우기

How to combine multiple ROI masks (.nii files) into one .nii file

조회 수: 72 (최근 30일)
Chia-Yueh Chang
Chia-Yueh Chang 2023년 4월 14일
답변: Sarthak 2023년 4월 18일
HI
How to combine multiple ROI masks (.nii files) into one .nii file?
for example, if I have the right amygdala.nii and left amygdala.nii, how can I combine them into amygdala with both sides?
furthermore, if I have the right, left, anterior and posterior side of insula, how can I combine them into one file as insula?
I've tried the script below,
but while I check the "add overlay function" with MRIcroGL, there's nothing:
clear all;
clc;
ROIFolder=['D:\000ROIMask\AMG'];
cd(ROIFolder);
% ROIFolder=fullfile(pwd, '\functional');
files=dir(fullfile(ROIFolder, '*.nii'));
fileNames={files.name};
for k = 1:numel(fileNames)
fname = fullfile(ROIFolder, fileNames{k});
z(k) = load_nii(fname);
y(:,:,:,k) = z(k).img;
end
% Create the ND Nifti file
output = make_nii(y);
% Save it to a file
save_nii(output, 'myfile.nii')
Thank you so much for your help...
Rainbow

답변 (1개)

Sarthak
Sarthak 2023년 4월 18일
Hi Chia-Yueh Chang,
As per my understanding your approach seems correct. However, you are not specifying the combined ROI mask using any logical operations, which could be the reason why you are not seeing any overlay when checking with MRIcroGL.
To combine the multiple ROI masks into one mask, you need to use logical operations (e.g., or, and, etc.) on the voxel values of the loaded .nii files.
After loading your files, you may modify your code as
% Combine the ROI masks using logical OR operation along the 4th dimension
combined_mask = any(y, 4);
% Create a new NIfTI structure for the combined mask
output = make_nii(combined_mask);
% Save the combined mask as a new .nii file
save_nii(output, 'myfile.nii');
Please note that the resulting combined mask may need to be thresholded or processed further depending on your specific use case and requirements.
Attaching some documentation for your reference

카테고리

Help CenterFile Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by