matRad_exportDicomCt

Purpose ^

matRad function to export ct to dicom.

Synopsis ^

function obj = matRad_exportDicomCt(obj)

Description ^

 matRad function to export ct to dicom. 
 Class method of matRad_DicomExporter
 
 call
   matRad_DicomExporter.matRad_exportDicomCt()


 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.

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

Cross-reference information ^

This function calls: This function is called by:

Source code ^

0001 function obj = matRad_exportDicomCt(obj)
0002 % matRad function to export ct to dicom.
0003 % Class method of matRad_DicomExporter
0004 %
0005 % call
0006 %   matRad_DicomExporter.matRad_exportDicomCt()
0007 %
0008 %
0009 % References
0010 %   -
0011 %
0012 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 %
0014 % Copyright 2019 the matRad development team.
0015 %
0016 % This file is part of the matRad project. It is subject to the license
0017 % terms in the LICENSE file found in the top-level directory of this
0018 % distribution and at https://github.com/e0404/matRad/LICENSES.txt. No part
0019 % of the matRad project, including this file, may be copied, modified,
0020 % propagated, or distributed except according to the terms contained in the
0021 % LICENSE file.
0022 %
0023 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 matRad_cfg = MatRad_Config.instance();
0026 
0027 matRad_cfg.dispInfo('Exporting DICOM CT...');
0028 
0029 %default meta
0030 meta.PatientName         = obj.PatientName;
0031 meta.PatientID           = obj.PatientID;
0032 meta.PatientBirthDate    = obj.PatientBirthDate;
0033 meta.PatientSex          = obj.PatientSex;
0034 meta.PatientPosition     = obj.PatientPosition;
0035 meta.StudyID             = obj.StudyID;
0036 meta.StudyDate           = obj.StudyDate;
0037 meta.StudyTime           = obj.StudyTime;
0038 meta.StudyInstanceUID    = obj.StudyInstanceUID;
0039 meta.FrameOfReferenceUID = obj.FrameOfReferenceUID;
0040 
0041 ClassUID = '1.2.840.10008.5.1.4.1.1.2'; %CT Image
0042 meta.MediaStorageSOPClassUID = ClassUID;
0043 meta.SOPClassUID = ClassUID;
0044 %TransferSyntaxUID = '1.2.840.10008.1.2';
0045 %meta.TransferSyntaxUID = TransferSyntaxUID;
0046 
0047 %Identifiers
0048 meta.SOPInstanceUID             = dicomuid;
0049 meta.MediaStorageSOPInstanceUID = meta.SOPInstanceUID;
0050 meta.SeriesInstanceUID          = dicomuid;
0051 meta.SeriesNumber               = 1;
0052 meta.InstanceNumber             = 1;
0053 
0054 
0055 obj.ctMeta.SeriesInstanceUID = dicomuid;
0056 meta.SeriesInstanceUID       = obj.ctMeta.SeriesInstanceUID;
0057 
0058 meta.SeriesNumber      = 1;
0059 meta.AcquisitionNumber = 1;
0060 meta.InstanceNumber    = 1;
0061 
0062 meta.Modality               = 'CT';
0063 meta.ReferringPhysicianName = obj.dicomName();
0064 meta.PatientPosition        = obj.PatientPosition;
0065 
0066 
0067 ct = obj.ct;
0068 
0069 nSlices = ct.cubeDim(3);
0070 %Create X Y Z vectors if not present
0071 if ~any(isfield(ct,{'x','y','z'}))
0072     %positionOffset = transpose(ct.cubeDim ./ 2);
0073     positionOffset = ct.cubeDim ./ 2;
0074     ct.x = ct.resolution.x*[0:ct.cubeDim(2)-1] - positionOffset(2);
0075     ct.y = ct.resolution.y*[0:ct.cubeDim(1)-1] - positionOffset(1);
0076     ct.z = ct.resolution.z*[0:ct.cubeDim(3)-1] - positionOffset(3);
0077 end
0078 
0079 obj.ct = ct;
0080 
0081 %Since we are exporting HU directly --> no rescaling in any case
0082 meta.SliceThickness = ct.resolution.z;
0083 meta.PixelSpacing   = [ct.resolution.y; ct.resolution.x];
0084 meta.ImageOrientationPatient = [1;0;0;0;1;0]; %lps
0085 meta.RescaleType = 'HU';
0086 
0087 if isfield(ct,'z')
0088     z = ct.z;
0089 end
0090 
0091 ctCube = ct.cubeHU{1};
0092 ctMin  = min(ctCube(:));
0093 ctCube = ctCube - ctMin;
0094 ctMax  = max(ctCube(:));
0095 ctCube = ctCube ./ ctMax;
0096 ctCube = uint16(ctCube*double(uint16(Inf)));
0097 
0098 meta.RescaleIntercept = ctMin;
0099 meta.RescaleSlope     = ctMax / double(uint16(Inf) + 1);
0100 
0101 meta.ImageType = 'DERIVED\PRIMARY\AXIAL';
0102 
0103 fileName = 'ct_slice_';
0104 
0105 obj.ctSliceMetas   = struct([]);
0106 obj.ctExportStatus = struct([]);
0107 
0108 
0109 for i = 1:nSlices
0110     ctSlice = ctCube(:,:,i);
0111     %ctSlice = permute(ctSlice,[1 2]);
0112     
0113     obj.ctSliceMetas = obj.addStruct2StructArray(obj.ctSliceMetas,meta);
0114     
0115     obj.ctSliceMetas(i).ImagePositionPatient = [ct.x(1); ct.y(1); ct.z(i)];
0116     
0117     obj.ctSliceMetas(i).SlicePositions = z(i);
0118     
0119     %Create and store unique ID
0120     obj.ctSliceMetas(i).SOPClassUID    = ClassUID;
0121     
0122     fullFileName = fullfile(obj.dicomDir,[fileName num2str(i) '.dcm']);
0123     if matRad_cfg.isOctave
0124         obj.ctSliceMetas(i).SOPInstanceUID = dicomuid;
0125         obj.ctSliceMetas(i).MediaStorageSOPInstanceUID = obj.ctSliceMetas(i).SOPInstanceUID;
0126     
0127         dicomwrite(ctSlice,fullFileName,obj.ctSliceMetas(i));
0128     else
0129         status = dicomwrite(ctSlice,fullFileName,obj.ctSliceMetas(i),'ObjectType','CT Image Storage');
0130         obj.ctExportStatus = obj.addStruct2StructArray(obj.ctExportStatus,status);
0131         
0132         %We need to get the info of the file just written because of Matlab's
0133         %hardcoded way of generating InstanceUIDs during writing
0134         tmpInfo = dicominfo(fullFileName);
0135         obj.ctSliceMetas(i).SOPInstanceUID              = tmpInfo.SOPInstanceUID;
0136         obj.ctSliceMetas(i).MediaStorageSOPInstanceUID  = tmpInfo.MediaStorageSOPInstanceUID;
0137     end   
0138     
0139     matRad_progress(i,nSlices);
0140     
0141 end
0142 
0143 end
0144

| Generated by m2html © 2005