Niftiwrite throws error even when just saving the image

조회 수: 45 (최근 30일)
Emilia Butters
Emilia Butters 2024년 6월 28일
답변: Emilia Butters 2024년 6월 28일
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