matRad_importPatient

Purpose ^

matRad patient import from binary files (CT and masks)

Synopsis ^

function [ct,cst] = matRad_importPatient(ctFile,maskFiles,hlutFilename)

Description ^

 matRad patient import from binary files (CT and masks)
 
 call
   [ct,cst] = matRad_importPatient(cubeFile,maskFiles)
   [ct,cst] = matRad_importPatient(cubeFile,maskFiles, hlutFilename)

 input
   ctFile:     path to CT file. If HLUT is not set, values are interpreted
               as HU and interpolated to ED. 
   maskFiles:  cell array with filenames to the masks
               if maskFiels contains a folder, all contained and
               recognized data files are treated as masks
   hlutFilname:(optional) HLUT, (n,2) array. if set to 'default', we will
               use a default HLUT
 output
   ct          ct struct for use with matlab
   cst         cst struct for use with matlab


 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 Copyright 2015 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.

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Cross-reference information ^

This function calls: This function is called by:

Subfunctions ^

Source code ^

0001 function [ct,cst] = matRad_importPatient(ctFile,maskFiles,hlutFilename)
0002 % matRad patient import from binary files (CT and masks)
0003 %
0004 % call
0005 %   [ct,cst] = matRad_importPatient(cubeFile,maskFiles)
0006 %   [ct,cst] = matRad_importPatient(cubeFile,maskFiles, hlutFilename)
0007 %
0008 % input
0009 %   ctFile:     path to CT file. If HLUT is not set, values are interpreted
0010 %               as HU and interpolated to ED.
0011 %   maskFiles:  cell array with filenames to the masks
0012 %               if maskFiels contains a folder, all contained and
0013 %               recognized data files are treated as masks
0014 %   hlutFilname:(optional) HLUT, (n,2) array. if set to 'default', we will
0015 %               use a default HLUT
0016 % output
0017 %   ct          ct struct for use with matlab
0018 %   cst         cst struct for use with matlab
0019 %
0020 %
0021 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 %
0023 % Copyright 2015 the matRad development team.
0024 %
0025 % This file is part of the matRad project. It is subject to the license
0026 % terms in the LICENSE file found in the top-level directory of this
0027 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0028 % of the matRad project, including this file, may be copied, modified,
0029 % propagated, or distributed except according to the terms contained in the
0030 % LICENSE file.
0031 %
0032 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 
0034 
0035 [cube, metadata] = matRad_readCube(ctFile);
0036 
0037 ct = struct();
0038 cst = cell(0,6);
0039 
0040 ct.cubeHU{1} = cube;
0041 
0042 if nargin == 3
0043     HLUT = matRad_readHLUT(hlutFilename);
0044     ct.cube{1} = interp1(HLUT(:,1),HLUT(:,2),double(cube));
0045     ct.hlut = HLUT;
0046 end
0047 
0048 ct.cubeDim = metadata.cubeDim;
0049 ct.resolution.x = metadata.resolution(1);
0050 ct.resolution.y = metadata.resolution(2);
0051 ct.resolution.z = metadata.resolution(3);
0052     
0053 ct.numOfCtScen = 1;
0054 
0055 maskId = 1;
0056 hGlobalWaitbar = waitbar(0,'Importing Segmentations');
0057 set(findall(hGlobalWaitbar,'type','text'),'Interpreter','none');
0058 
0059 
0060 
0061 for f=1:numel(maskFiles)
0062     maskFile = maskFiles{f};
0063     waitbar(f/numel(maskFiles),hGlobalWaitbar,['Importing Segmentations: ' maskFiles{f}]);
0064     if exist(maskFile,'dir')
0065         contents = dir(maskFile);
0066         hFolderWaitbar = waitbar(0,'Importing Folder');
0067         set(findall(hFolderWaitbar,'type','text'),'Interpreter','none');
0068         for s=1:numel(contents)
0069             waitbar(s/numel(contents),hFolderWaitbar,['Importing Folder: ' contents(s).name]);            
0070             if(~contents(s).isdir)
0071                 [mask, maskMeta] = matRad_readCube(fullfile(maskFile,contents(s).name));
0072                 cstLine = importMaskToCstLine(maskId,mask,maskMeta);
0073                 cst = [cst; cstLine]; 
0074                 maskId = maskId + 1;
0075             end            
0076         end
0077         delete(hFolderWaitbar);
0078     elseif exist(maskFile,'file')
0079         [mask,maskMeta] = matRad_readCube(maskFile);  
0080         cstLine = importMaskToCstLine(maskId,mask,maskMeta);
0081         cst = [cst; cstLine];           
0082         maskId = maskId + 1;
0083     else
0084         disp(['Ignored file/dir ' maskFile '!']);
0085     end
0086 end
0087 
0088 delete(hGlobalWaitbar);
0089 
0090 
0091 %Assign default colors
0092 colors = colorcube(size(cst,1));
0093 for i = 1:size(cst,1)
0094     cst{i,5}.visibleColor = colors(i,:);
0095 end
0096 
0097 end
0098 
0099 function cstLine = importMaskToCstLine(maskId,mask,maskMeta)  
0100     cstLine = cell(1,6);
0101     cstLine{1} = maskId - 1;
0102     cstLine{2} = maskMeta.name;
0103     cstLine{3} = tryToGetVoiTypeByName(maskMeta.name);
0104     cstLine{4}{1} = find(mask > 0);
0105     cstLine{5}.Priority = maskId;
0106     cstLine{5}.alphaX = 0.1;
0107     cstLine{5}.betaX = 0.05;
0108     cstLine{5}.Visible = 1;
0109 end
0110 
0111 function type = tryToGetVoiTypeByName(voiName)
0112     targetNames = {'target'; 'ptv'; 'ctv'};
0113     for n=1:numel(targetNames)
0114         found = strfind(lower(voiName),lower(targetNames{n}));
0115         if ~isempty(found)
0116             type = 'TARGET';
0117             return;
0118         end
0119     end
0120     type = 'OAR';
0121 end
0122 
0123

| Generated by m2html © 2005