matRad mhd file reader call cube = matRad_readMhd(folder,filename) input folder: folder where the *raw and *mhd file are located filename: filename output cube: 3D array References %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright 2019 the matRad development team. This file is part of the matRad project. It is subject to the license terms in the LICENSE file found in the top-level directory of this distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part of the matRad project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the LICENSE file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function cube = matRad_readMhd(folder,filename) 0002 % matRad mhd file reader 0003 % 0004 % call 0005 % cube = matRad_readMhd(folder,filename) 0006 % 0007 % input 0008 % folder: folder where the *raw and *mhd file are located 0009 % filename: filename 0010 % 0011 % output 0012 % cube: 3D array 0013 % 0014 % References 0015 % 0016 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0017 % 0018 % Copyright 2019 the matRad development team. 0019 % 0020 % This file is part of the matRad project. It is subject to the license 0021 % terms in the LICENSE file found in the top-level directory of this 0022 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part 0023 % of the matRad project, including this file, may be copied, modified, 0024 % propagated, or distributed except according to the terms contained in the 0025 % LICENSE file. 0026 % 0027 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0028 0029 0030 %% read header 0031 headerFileHandle = fopen([folder filesep filename],'r'); 0032 0033 s = textscan(headerFileHandle, '%s', 'delimiter', '\n'); 0034 0035 % read dimensions 0036 idx = find(~cellfun(@isempty,strfind(s{1}, 'DimSize')),1,'first'); 0037 dimensions = cell2mat(textscan(s{1}{idx},'DimSize = %f %f %f')); 0038 0039 % read filename of data 0040 idx = find(~cellfun(@isempty,strfind(s{1}, 'ElementDataFile')),1,'first'); 0041 tmp = textscan(s{1}{idx},'ElementDataFile = %s'); 0042 dataFilename = cell2mat(tmp{1}); 0043 0044 % get data type 0045 idx = find(~cellfun(@isempty,strfind(s{1}, 'ElementType')),1,'first'); 0046 tmp = textscan(s{1}{idx},'ElementType = MET_%s'); 0047 type = lower(cell2mat(tmp{1})); 0048 0049 fclose(headerFileHandle); 0050 0051 %% read data 0052 dataFileHandle = fopen([folder filesep dataFilename],'r'); 0053 cube = reshape(fread(dataFileHandle,inf,type),dimensions); 0054 cube = permute(cube,[2 1 3]); 0055 cube = flip(cube,2); 0056 fclose(dataFileHandle);