Writing 3D array to BMP file
显示 更早的评论
I have a data structure which contains a 3D array (852x512x16) of MRI image data. I need to export this image as a .bmp file. I tried doing this with the save() function (commented below) which seemed to work, but the 3rd party app (Materialise Mimics) that I need to use to process the image said the file type was not recognized, even though the software is definitely capable of working with bmp files (I've done so with other files). To verify that the issue was the file and not the program I tried viewing the bmp in ImageJ and was thrown an error: "java.lang.ArithmeticException: / by zero".
I then tried using the imwrite() function instead but received an error.
clear; clc; close all;
load('PatientImages_1_T2.mat') % load data structure
img=(PatientImages.originalimage(:,:,:)); % extract all 16 slices from struct
% img is now an 852 x 512 x 16 array
filename='patient1_t2';
%save('patient1_t2.bmp','img'); % file not recognized by Mimics
imwrite(img,filename,'bmp')
Error message:
"Error using writebmp (line 27)
Invalid dimensions for X.
Error in imwrite (line 566)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in struct2bmp (line 7)
imwrite(img,filename,'bmp')"
I'm assuming from the error message that the problem is that my image has multiple slices and is a z-stack. Do I need to do some kind of operation slice by slice and then collate them together in one bmp at the end somehow?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!