フィルターのクリア

how to open image .mhd

44 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2024 年 6 月 29 日 9:11
回答済み: DGM 2024 年 6 月 29 日 20:39
DEAR ALL,
Anyone know how to open this image as attached.

採用された回答

DGM
DGM 2024 年 6 月 29 日 20:39
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 日 12:10
Hi mohd,
I hope it resolves your query!

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by