[filename, filepath] = uigetfile('*.raw', 'Select image to view');
%This part allows users to show the first slice
% --- display file path and file name
handles.imagefilename = filename;
handles.imagefilepath = filepath;
fullpath = [filepath filename];
%store the raw image into V available in the workspace for further display
NumX=256;
NumY=256;
NumZ=220;
VoxelDataType ='short';
fid = fopen(fullpath); %open the file
V = fread(fid,[NumX*NumY NumZ],VoxelDataType); %each slice will be read in as a column
V = reshape(V,[NumX NumY NumZ]); %reshape to the size of the input image
fclose(fid); %clean up the memory
h = slice(V, [], [], 1:1:size(V,3));
set(h, 'EdgeColor','none', 'FaceColor','interp')
alpha(.1)
参考
https://ww2.mathworks.cn/matlabcentral/fileexchange/36172-a-matlab-viewer-for-3d-raw-images