Radiomics - github code https://gi​thub.com/m​vallieres/​radiomics

9 Ansichten (letzte 30 Tage)
M Philip
M Philip am 21 Feb. 2021
Kommentiert: M Philip am 23 Feb. 2021
Hello,
I have a problem running the following github code used for reading a DICOM image of H&N cancer from The Cancer Imaging Archive(TCIA) in the windows platform. A function named sData is declared, but in the output sData{4} and sData{5} are empty, but I need data in that array to run the next code to compute ROI. I tried with all the image data set but the array is always empty. I am doubtful since I use windows, is there a different condition for line 69 as it is mentioned 'Good enough for Linux, add conditions for MAC and Windows' and I do not know which conditions to use. If any one has previously done this please do help.
function [sData] = readDICOMdir(dicomPath,waitB)
% -------------------------------------------------------------------------
% function [sData] = readDICOMdir(dicomPath,waitB)
% -------------------------------------------------------------------------
% DESCRIPTION:
% This function reads the DICOM content of a single directory. It then
% organizes the data it in a cell of structures called 'sData', and
% computes the region of interest (ROI) defined by a given RTstruct (if
% present in the directory).
% -------------------------------------------------------------------------
% INPUTS:
% - dicomPath: Full path where the DICOM files to read are located.
% - waitB: Logical boolean. If true, a waiting bar will be displayed.
% -------------------------------------------------------------------------
% OUTPUTS:
% - sData: Cell of structures organizing the content of the volume data,
% DICOM headers, DICOM RTstruct* (used to compute the ROI) and
% DICOM REGstruct* (used to register a MRI volume to a PET volume)
% * If present in the directory
% --> sData{1}: Explanation of cell content
% --> sData{2}: Imaging data and ROI defintion (if applicable)
% --> sData{3}: DICOM headers of imaging data
% --> sData{4}: DICOM RTstruct (if applicable)
% --> sData{5}: DICOM REGstruct (if applicable)
% -------------------------------------------------------------------------
% AUTHOR(S):
% - Martin Vallieres <mart.vallieres@gmail.com>
% - Sebastien Laberge <sebastien.laberge.3000@gmail.com>
% -------------------------------------------------------------------------
% HISTORY:
% - Creation: May 2015
%--------------------------------------------------------------------------
% STATEMENT:
% This file is part of <https://github.com/mvallieres/radiomics/>,
% a package providing MATLAB programming tools for radiomics analysis.
% --> Copyright (C) 2015 Martin Vallieres, Sebastien Laberge
%
% This package is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This package is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this package. If not, see <http://www.gnu.org/licenses/>.
% -------------------------------------------------------------------------
% INITIALIZATION
if waitB
waitbarHandle = waitbar(0,'Loading DICOM files...','WindowStyle','modal');
end
elements = dir(dicomPath);
nElements = length(elements);
volume = cell(1,1,nElements);
dicomHeaders = [];
RTstruct = [];
REG = [];
% READING DIRECTORY CONTENT
sliceNumber = 0;
for elementNumber = 1:nElements
elementName = elements(elementNumber).name;
if ~strcmp(elementName,'.') && ~strcmp(elementName,'..') % Good enough for Linux, add conditions for MAC and Windows.
elementFullFile = fullfile(dicomPath,elementName);
if isdicom(elementFullFile)
tmp = dicominfo(elementFullFile);
if strcmp(tmp.Modality,'RTSTRUCT')
RTstruct = tmp;
elseif strcmp(tmp.Modality,'REG')
REG = tmp;
elseif strcmp(tmp.Modality,'MR') || strcmp(tmp.Modality,'PT') || strcmp(tmp.Modality,'CT')
sliceNumber = sliceNumber + 1;
volume{sliceNumber} = double(dicomread(elementFullFile));
dicomHeaders = appendStruct(dicomHeaders,tmp);
end
end
end
if waitB
waitbar(elementNumber/nElements,waitbarHandle);
end
end
nSlices = sliceNumber; % Total number of slices
volume = volume(1:nSlices); % Suppress empty cells in images
% DETERMINE THE SCAN ORIENTATION
dist = [abs(dicomHeaders(2).ImagePositionPatient(1) - dicomHeaders(1).ImagePositionPatient(1)), ...
abs(dicomHeaders(2).ImagePositionPatient(2) - dicomHeaders(1).ImagePositionPatient(2)), ...
abs(dicomHeaders(2).ImagePositionPatient(3) - dicomHeaders(1).ImagePositionPatient(3))];
[~,index] = max(dist);
if index == 1
orientation = 'Sagittal';
elseif index == 2
orientation = 'Coronal';
else
orientation = 'Axial';
end
% SORT THE IMAGES AND DICOM HEADERS
slicePositions = zeros(1,nSlices);
for sliceNumber = 1:nSlices
slicePositions(sliceNumber) = dicomHeaders(sliceNumber).ImagePositionPatient(index);
end
[~,indices] = sort(slicePositions);
volume = cell2mat(volume(indices));
dicomHeaders = dicomHeaders(indices);
% FILL sData
sData = cell(1,5);
type = dicomHeaders(1).Modality;
if strcmp(type,'PT') || strcmp(type,'CT')
if strcmp(type,'PT')
type = 'PET';
end
for i=1:size(volume,3)
volume(:,:,i)=volume(:,:,i)*dicomHeaders(i).RescaleSlope + dicomHeaders(i).RescaleIntercept;
end
end
type = [type,'scan'];
sData{1} = struct('Cell_1','Explanation of cell content', ...
'Cell_2','Imaging data and ROI defintion (if applicable)', ...
'Cell_3','DICOM headers of imaging data', ...
'Cell_4','DICOM RTstruct (if applicable)', ...
'Cell_5','DICOM REGstruct (if applicable)');
sData{2}.scan.volume = volume;
sData{2}.scan.orientation = orientation;
try sData{2}.scan.pixelW = dicomHeaders(1).PixelSpacing(1); catch, sData{2}.scan.pixelW = []; end % Pixel Width
try sData{2}.scan.sliceT = dicomHeaders(1).SliceThickness; catch, sData{2}.scan.sliceT = []; end % Slice Thickness
s1 = round(0.5*nSlices); s2 = round(0.5*nSlices) + 1; % Slices selected to calculate slice spacing
sData{2}.scan.sliceS = sqrt(sum((dicomHeaders(s1).ImagePositionPatient - dicomHeaders(s2).ImagePositionPatient).^2)); % Slice Spacing
sData{2}.type = type;
sData{3} = dicomHeaders;
sData{4} = RTstruct;
sData{5} = REG;
% COMPUTE TUMOR DELINEATION USING RTstruct
if ~isempty(sData{4})
[sData] = computeROI(sData);
end
if waitB
close(waitbarHandle)
end
end
% UTILITY FUNCTION
function [structureArray] = appendStruct(structureArray,newStructure)
if isempty(structureArray)
structureArray = newStructure;
return
end
structLength = length(structureArray);
fields = fieldnames(structureArray(1));
nFields = length(fields);
for i = 1:nFields
try
structureArray(structLength + 1).(fields{i}) = newStructure.(fields{i});
catch
structureArray(structLength + 1).(fields{i}) = 'FIELD NOT PRESENT';
end
end
end
Many thanks

Akzeptierte Antwort

Mario Malic
Mario Malic am 21 Feb. 2021
Bearbeitet: Mario Malic am 21 Feb. 2021
Hi Philip,
The code should work, does it?
Edited as per Walter's note
When you use dir specifying folder as an input argument, entries with name '.', '..' will appear somewhere in your dir structure.
This if statement is used just to avoid those two rows, because isdicom will produce an error when you supply to it the path that doesn't lead to an actual file.
if ~strcmp(elementName,'.') && ~strcmp(elementName,'..')
  28 Kommentare
Mario Malic
Mario Malic am 23 Feb. 2021
Bearbeitet: Mario Malic am 23 Feb. 2021
Yay! I am glad it worked!
This code worked? Or, did you use one of those linked functions?
mask(:,:,sliceOK) = false(sizeScan(1),sizeScan(2));
Well, I do not know if I will be able to help, but here's the thing with this forum. If you can describe your question and problem precisely, provide files needed to run the code, it's very very likely that someone will help you. There are few people here who know a lot about medical imaging, including DICOM files.
M Philip
M Philip am 23 Feb. 2021
I used the code which you gave.
mask(:,:,sliceOK) = false(sizeScan(1),sizeScan(2));
Thanks for sharing the useful links. I will learn how to ask questions which are very precise.
I really appreciate your help!
Thanks again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by