Effacer les filtres
Effacer les filtres

how to open image .mhd

43 vues (au cours des 30 derniers jours)
mohd akmal masud
mohd akmal masud le 29 Juin 2024 à 9:11
Réponse apportée : DGM le 29 Juin 2024 à 20:39
DEAR ALL,
Anyone know how to open this image as attached.

Réponse acceptée

DGM
DGM le 29 Juin 2024 à 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),[]);

Plus de réponses (1)

Shivansh
Shivansh le 29 Juin 2024 à 12:10
Hi mohd,
I hope it resolves your query!

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by