Niftiwrite throws error even when just saving the image

43 ビュー (過去 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 Center および File Exchange3-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