Niftiwrite throws error even when just saving the image

45 Ansichten (letzte 30 Tage)
Emilia Butters
Emilia Butters am 28 Jun. 2024
Beantwortet: Emilia Butters am 28 Jun. 2024
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 Kommentar
Cris LaPierre
Cris LaPierre am 28 Jun. 2024
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);

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Aditya
Aditya am 28 Jun. 2024
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 am 28 Jun. 2024
Resolved! The Pixel dimensions were incorrect (4 dimensional for what was supposed to be a 3D strucutral image

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by