123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- function Geometry = dicomrt2geometry(dicomrt_dir)
- Geometry = [];
- if nargin < 1
- load('WiscPlan_preferences.mat')
-
- if isstring(WiscPlan_preferences.inDataPath)
- else
- WiscPlan_preferences.inDataPath = 'C://';
- end
- dicomrt_dir = uigetdir(WiscPlan_preferences.inDataPath, 'Select the directory contains the DICOM-RT images');
-
- WiscPlan_preferences.inDataPath = dicomrt_dir;
- thisDir = mfilename('fullpath');
- idcs = strfind(thisDir,'\');
- prefsdir = thisDir(1:idcs(end-1)-1);
- save([prefsdir '\WiscPlan_preferences.mat'], 'WiscPlan_preferences')
- end
- if exist(dicomrt_dir, 'dir') ~= 7
- msgbox('Cannot find input directory');
- return;
- end
- dicomdict('factory');
- previousPath = pwd;
- cd(dicomrt_dir);
- dirlist = dir(dicomrt_dir);
- filenames = cell(0);
- for i = 1:numel(dirlist)
- [tilde, tilde, ext] = fileparts(dirlist(i).name);
- if ~dirlist(i).isdir && ~strcmpi(ext, '.txt')
- filenames{end+1} = dirlist(i).name;
- end
- end
- for i = 1:numel(filenames)
- dcminfo{i} = dicominfo(filenames{i});
- end
- fid = fopen('ctlist.txt', 'w');
- for i = 1:numel(dcminfo)
- if strcmpi(dcminfo{i}.Modality, 'CT')
- fprintf(fid, '%s\n', filenames{i});
- end
- end
- fclose(fid);
- [cellCt, ct_xmesh, ct_ymesh, ct_zmesh] = dicomrt_loadct('ctlist.txt');
- button = questdlg('Do you want to downsample the CT dataset?', 'Downsampling', 'Yes', 'No', 'Yes');
- if strcmpi(button, 'yes')
- downsample_flag = true;
- else
- downsample_flag = false;
- end
- for i = 1:numel(dcminfo)
- if strcmpi(dcminfo{i}.Modality, 'RTSTRUCT')
- rsfilename = fullfile(dicomrt_dir, filenames{i});
- end
- end
- if isempty(rsfilename)
- [temp_FileName temp_PathName] = uifile('get', '*.dcm', 'Please select the DicomRT-Struct file');
- rsfilename = fullfile(temp_PathName, temp_FileName);
- end
- cellVoi = dicomrt_loadvoi(rsfilename);
- if downsample_flag == true
- if numel(ct_xmesh) < 128
- downsample_factor = 0.5;
- dx = ct_xmesh(2)-ct_xmesh(1);
- dy = ct_ymesh(2)-ct_ymesh(1);
- ct_xmesh = linspace(ct_xmesh(1)+dx/2, ct_xmesh(end)-dx/2, numel(ct_xmesh)*downsample_factor);
- ct_ymesh = linspace(ct_ymesh(1)+dy/2, ct_ymesh(end)-dy/2, numel(ct_ymesh)*downsample_factor);
- else
- downsample_factor = 0.125;
- downsample_factor = 1/8;
- dx = ct_xmesh(2)-ct_xmesh(1);
- dy = ct_ymesh(2)-ct_ymesh(1);
- ct_xmesh = linspace(ct_xmesh(1)+dx/2, ct_xmesh(end)-dx/2, numel(ct_xmesh)*downsample_factor);
- ct_ymesh = linspace(ct_ymesh(1)+dy/2, ct_ymesh(end)-dy/2, numel(ct_ymesh)*downsample_factor);
- end
- end
- ROIS = dicomrt_rasterizeVoi(cellVoi, cellCt, ct_xmesh, ct_ymesh, ct_zmesh);
- cd(previousPath);
- Geometry.ROIS = ROIS;
- Geometry.data = cellCt{2};
- Geometry.voxel_size = abs([ct_xmesh(2)-ct_xmesh(1) ...
- ct_ymesh(2)-ct_ymesh(1) ...
- ct_zmesh(2)-ct_zmesh(1)]);
- Geometry.start = [ct_xmesh(1) ct_ymesh(1) ct_zmesh(1)];
- if downsample_flag == true
- Geometry.data = resamplegrid(Geometry.data, [downsample_factor downsample_factor 1]);
-
-
- Geometry.start(1:2) = Geometry.start(1:2) + Geometry.voxel_size(1:2) / 4;
- end
- Geometry.rhomw = CT2dens(Geometry.data, 'pinn');
- Geometry.rhomw(Geometry.rhomw < 0.0012) = 0.0012;
- [Geometry.Smw Geometry.Fmw2] = dens2mstp(Geometry.rhomw);
|