Filter löschen
Filter löschen

how to open image .mhd

43 Ansichten (letzte 30 Tage)
mohd akmal masud
mohd akmal masud am 29 Jun. 2024 um 9:11
Beantwortet: DGM am 29 Jun. 2024 um 20:39
DEAR ALL,
Anyone know how to open this image as attached.

Akzeptierte Antwort

DGM
DGM am 29 Jun. 2024 um 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),[]);

Weitere Antworten (1)

Shivansh
Shivansh am 29 Jun. 2024 um 12:10
Hi mohd,
I hope it resolves your query!

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by