how to open image .mhd

9 次查看(过去 30 天)
mohd akmal masud
mohd akmal masud 2024-6-29
回答: DGM 2024-6-29
DEAR ALL,
Anyone know how to open this image as attached.

采纳的回答

DGM
DGM 2024-6-29
I don't know about the format, but here's a start. That should give you a volumetric image. Note that the data range is very narrow for its class, so it may require scaling just for viewing. Beyond that , the contrast still seems odd, so I don't know if there is other scaling that needs to be done.
fbasename = 'doseMonteCarlo1HR-Dose';
% read the header file and tokenize it
hdrstr = splitlines(fileread([fbasename '.mhd']));
hdrtok = regexp(hdrstr,'^(\w+)\s?=\s?(.+)$','tokens');
% reformat/clean the extracted info and shove it in a cell array
% i'm assuming that the field names always have the same case
hdrinfo = cell(0,2);
for k = 1:numel(hdrtok)-1
thisline = hdrtok{k}{:};
hdrinfo{k,1} = thisline{1};
switch hdrinfo{k,1}
case 'NDims'
hdrinfo{k,2} = str2double(thisline{2});
case {'TransformMatrix','Offset','CenterOfRotation','ElementSpacing','DimSize'}
hdrinfo{k,2} = str2num(thisline{2}); %#ok<ST2NM>
case {'BinaryData','BinaryDataByteOrderMSB','CompressedData'}
hdrinfo{k,2} = strcmpi(thisline{2},'True');
otherwise
hdrinfo{k,2} = thisline{2};
end
end
% convert it to a struct
hdrinfo = cell2struct(hdrinfo(:,2),hdrinfo(:,1),1)
% get the machine format parameter for fread
if hdrinfo.BinaryDataByteOrderMSB
machfmt = 'ieee-be';
else
machfmt = 'ieee-le';
end
% read the file according to the header info
fid = fopen(hdrinfo.ElementDataFile);
switch hdrinfo.ElementType
case 'MET_SHORT'
inpict = fread(fid,'*int16',machfmt);
case 'MET_FLOAT'
inpict = fread(fid,'*float32',machfmt);
otherwise
% idk what other formats are supported
% you'll have to figure that out
end
fclose(fid);
% reshape the data
inpict = reshape(inpict,hdrinfo.DimSize);
% view one slice rescaled
imshow(inpict(:,:,59),[]);

更多回答(1 个)

Shivansh
Shivansh 2024-6-29
Hi mohd,
I hope it resolves your query!

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by