Niftiwrite throws error even when just saving the image
조회 수: 45 (최근 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
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
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!