Niftiwrite throws error even when just saving the image

43 次查看(过去 30 天)
Hi, I was playing around with segementing/skull stripping and wanted to save the new image the the MRI header using niftiwrite. This gave me an error so I then tried to load the image and save it with the following code:
T1 = niftiread(fullfile(fpath, ['mri/', participant, '_T1.nii']));
T1_info = niftiinfo(fullfile(fpath, ['mri/', participant, '_T1.nii']));
niftiwrite(T1, 'test.nii', T1_info);
Which then gave me the following error:
Error using niftiwrite>parseInputs (line 175)
The value of 'Info' is invalid. Volume size does not match header size specified.
Error in niftiwrite (line 89)
[V, path, filename, params] = parseInputs(V, filename, varargin{:});
I'm not allowed to share the MRI but any ideas why this is happening? Thanks!
  1 个评论
Cris LaPierre
Cris LaPierre 2024-6-28
Could you provide more details? I am unable to reproduce the error.using the brain.nii file that is included in MATLAB.
T1 = niftiread('brain.nii');
T1_info = niftiinfo('brain.nii');
niftiwrite(T1, 'test.nii', T1_info);

请先登录,再进行评论。

回答(2 个)

Aditya
Aditya 2024-6-28
Hi Emilla,
It sounds like you're encountering an issue with the "niftiwrite" function due to a mismatch between the volume size and the header size specified in the "niftiinfo" structure. This could be due to several reasons, such as changes in the image dimensions during processing or inconsistencies in the metadata.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
1) Verify Image Dimensions: Ensure the dimensions of T1 match T1_info.ImageSize
% Verify consistency
if ~isequal(size(T1), T1_info.ImageSize)
error('Image dimensions do not match header dimensions.');
end
2) Review Processing Steps: If the dimensions don't match, review the steps taken during image processing. Ensure that no operations inadvertently alter the image dimensions without updating the corresponding header information.
3) Minimal Reproducible Example:If the issue persists, try creating a minimal reproducible example using a sample NIfTI file that you can share. This will help others reproduce the error and provide more specific guidance.
I hope this helps!

Emilia Butters
Emilia Butters 2024-6-28
Resolved! The Pixel dimensions were incorrect (4 dimensional for what was supposed to be a 3D strucutral image

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by