Borrar filtros
Borrar filtros

how to open image .mhd

44 visualizaciones (últimos 30 días)
mohd akmal masud
mohd akmal masud el 29 de Jun. de 2024 a las 9:11
Respondida: DGM el 29 de Jun. de 2024 a las 20:39
DEAR ALL,
Anyone know how to open this image as attached.

Respuesta aceptada

DGM
DGM el 29 de Jun. de 2024 a las 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),[]);

Más respuestas (1)

Shivansh
Shivansh el 29 de Jun. de 2024 a las 12:10
Hi mohd,
I hope it resolves your query!

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by